angular controller
之间通过事件传递值
页面每次刷新路由都会对视图 ui-view
进行刷新,
绑定在内的控制器
angular.controller('listCtrl',[])
会进行重载,(因为我把 listCtrl
控制器绑定到了视图内的标签上)
controller
内的
$scope.$on('testData',function(ev,data){
//
})
会记录 listCtrl
重载的次数,等接收到 testData
事件的时候,$on
会重复执行相应的次数。
我只想让 testData
执行一次,应该怎么做
Thank you for the invitation, write a service or hang a global variable on $rootScope
Of course, regarding event subscription and sending, if it is not a situation like routing that requires notification to all scopes, it is recommended not to use the event mechanism that comes with AngularJS. It is recommended to write an EventBus service to handle it yourself. Because the event mechanism of AngularJS needs to traverse the entire scope tree, the performance is average.
Recommend an internal summary of our team:
https://github.com/ShuyunXIAN...