javascript - $rootScope Event not working Angularjs -
i have declared $rootscope.$on function under myapp.run check token value in every authenticated page.but not working.i not understand why not working.please me.
app.js
myapp.run(['$rootscope','$state', '$location', 'loginservice', function ($rootscope,$state, $location, loginservice) { console.log(" under run => "); $rootscope.$on('routechangestart', function (event, next, current) { /*if route authenticated check if user has access token, else return login screen*/ console.log(event); if (next.$$route.authenticated) { var userauth = loginservice.getusertoken(); console.log(" usertoken => " +userauth); if (!userauth) { $location.path("/"); } } }); }]);
code print on console "under run =>" not printing event object , not check if condition.
be care of $:
$rootscope.$on('$statechangestart',...)
Comments
Post a Comment