angular controller
through events
Every time the page refreshes the route, the view ui-view
will be refreshed,
Binded controller
angular.controller('listCtrl',[])
will be reloaded (because I bound the listCtrl
controller to the label in the view)
controller
within
$scope.$on('testData',function(ev,data){
//
})
will record the number of times listCtrl
is reloaded. When the testData
event is received, $on
will be executed repeatedly for the corresponding number of times.
I only want testData
to be executed once, what should I do
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...