AngularJS $routeChangeSuccess callback arguments
Asked Answered
C

1

15

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?

Closeup answered 24/7, 2014 at 16:17 Comment(0)
B
11

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.

Brasher answered 24/7, 2014 at 17:18 Comment(4)
Awesome. Thanks. I was getting frustrated trying to understand how some of the snippets I read were working.Closeup
Looking at both the JS source doc and the 1.2 docs, they both refer to the {Route} object. But I can't find the references to that either - only for the $route service. Am I not looking in the right places?Closeup
Forgive my being obtuse, but what is "The locals contain the resolved values of the resolve map." supposed to mean? I realize I'm new to Angular and all, but these API docs are making learning the blocks nearly impossible. How am I supposed to know/understand what fields/functions I have accessible from the $route object?Closeup
you can check the $routeProvider provider docs.angularjs.org/api/ngRoute/provider/$routeProvider regarding what a resolve means and other objects that may relate to the documentation I have provided above. Note: The when() method accepts a route definition as the second parameterBrasher

© 2022 - 2024 — McMap. All rights reserved.