What is Angular2 equivalent to AngularJS $ routeChangeStart?
In AngularJS
we were able to specify a route change event to observe changes in the route object using the event $routeChangeStart/End
$rootScope
. What is the equivalent of a route change event in Angular2?
how can we do this exact functionality below the code in Angular2
$scope.$on('$routeChangeStart', function (scope, next, current) {
//do what you want
});
I had some disagreements here, but I don't have the details anymore, so I asked a new question.
angular2 $ routeChangeStart, $ routeChangeSuccess, $ routeChangeError
source to share
You can listen for router events by doing the following:
import {
Router, ActivatedRoute,
NavigationEnd, NavigationStart,
NavigationError, NavigationCancel,
} from '@angular/router';
// constructor method of some angular element
constructor(
private _router: Router,
) {
this._router.events
.filter(event => event instanceof NavigationStart)
.subscribe(event => {
console.log("New route");
});
}
EDIT: I'm not entirely sure if this is really what you want, after looking more closely at the angularjs docs it seems that these events are more related to the resolution / result of the protection in angular2
source to share