AngularJS $routeChangeSuccess callback arguments

我只是一个虾纸丫 提交于 2019-12-01 14:13:25

问题


I'm new to AngularJS and am confused by the documentation regarding event listeners.

The documentation lists the following for the $routeChangeSuccess event:

$routeChangeSuccess Broadcasted after a route dependencies are resolved. ngView listens for the directive to instantiate the controller and render the view.

Type:

broadcast Target:

root scope

However, no where does it reference any arguments that are passed to the callback function. And yet, most of the examples I've seen here on SO all have a similar callback function listing:

$rootScope.$on("$routeChangeSuccess", function(event, next, current) {
   ...
});

According to the AngularJS docs, all callbacks have the first argument as the event. I get that. But where are next and current coming from? Where is that listed in any of the documentation?


回答1:


It was documented in version less than 1.2 see this old documentation. But it seems they haven't noticed that the callback signatures for their broadcast events are missing. On the other hand, if you don't mind reading from their github repository you can check this line here for the $routeChangeSuccess callback parameters.

Update: For the Route object you can actually refer to the $route properties documented here.



来源:https://stackoverflow.com/questions/24939006/angularjs-routechangesuccess-callback-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!