私は$ rootScope。その動作していない理由を理解していないのではないworking.I page.but認証されたすべてのトークン値をチェックするために$ myApp.run下機能上を宣言しました。私を助けてください。
は「実行=>下の」コンソール上
myApp.run(['$rootScope','$state', '$location', 'loginService', function ($rootScope,$state, $location, loginService) {
console.log(" under run => ");
$rootScope.$on('routeChangeStart', function (event, next, current) {
/*If route is authenticated then check if the user has access token, else return to login screen*/
console.log(event);
if (next.$$route.authenticated) {
var userAuth = loginService.getUserToken();
console.log(" usertoken => " +userAuth);
if (!userAuth) {
$location.path("/");
}
}
});
}]);
コード印刷をapp.jsが、それはイベントにオブジェクトを印刷していないし、また条件かどうかをチェックされていません。
私はこれが近いだと思うが、それはだ場合にのみ、UI-ルータはngRoute – shaunhusain
のために、それは、私は両方同じように考える私の一日;-) –
をSANE [この](HTTPをチェックするTNXを働くけれども、それはrouteChangeStartを$すべきだと思います。 //stackoverflow.com/questions/14765719/how-to-watch-for-a-route-change-in-angularjs)。 –