I'm not an AngularJS dev but I was handed a project.
Now I need to call the following method, every time a route changes. doesn't matter to which route, just any route.
window.Intercom("update");
Now I found the following piece of code.
function config($urlRouterProvider, $stateProvider, $translateProvider, $locationProvider, $httpProvider) {
So in that method I have access to the $urlRouterProvider , I read in the docs that here it's possible to check for matched routes, even with regex.
Now I'm wondering, is it possible to see any time the router changes url, Am I looking in the right direction?
If you're using the new Angular UI Router version 1.xx
You could just use a run block like so:
angular.module('whatever').run(function($transitions){
$transitions.onSuccess({}, function(){
window.Intercom("update");
});
});
If you're using the legacy version of Angular UI Router you could just subscribe to $stateChangeSuccess
events like so:
angular.module('whatever').run(function($rootScope){
$rootScope.$on('$stateChangeSuccess', function(){
window.Intercom("update");
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.