ng ui-route的toState, toParams, fromState, fromParams

xiaoxiao2021-02-28  134

平时开发的时候经常会遇到从几个页面跳到一个页面,最后还要原路返回的需求,原始的做法是通过页面传值实现,略显繁琐,angularjs有一种方法可以不用页面传值实现,用 fromState就可以判断出是从哪个页面过来的,再做相应的处理,具体使用方法如下代码所示:

$scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState,fromParams) { console.log('successfully changed states') ; console.log('event', event); console.log('toState', toState); console.log('toParams', toParams); console.log('fromState', fromState); console.log('fromParams', fromParams); });

使用$on来接收事件并作出响应

另外,使用ng还有一个问题就是怎么样控制器之间传值   关于控制器之间的传值这里有一篇文章说的很详细:Angular中$broadcast和$emit的使用方法

希望我的入坑经验对你有所帮助,愿圣光与你同在

转载请注明原文地址: https://www.6miu.com/read-29162.html

最新回复(0)