angularjs - $routeProvider - not load controller after failed resolve -
i'd check in router. in condition should redirect on anothter page.
i set router:
when('/login', { templateurl: 'login.html', controller: 'login', resolve : { 'checklogin': ['checklogin', function(checklogin){ return checklogin.islogin(); }] } }) and factory:
app.factory('checklogin', [function() { "use strict"; return { islogin: function() { if (loggin === 1) { $location.path('/home'); }; } }; }]); and if loggin === 1 redirects /home, calls login controller anyway. how can disable it? not fire login controller in case?
thanks
i decided use $locationchangestart advised @pankajparkar.
app.run(['$rootscope', '$location', function($rootscope, $location) { "use strict"; $rootscope.$on('$locationchangestart', function(event, next, current) { if (next.indexof('login') !== -1) { if (loggin === 1) { event.preventdefault(); $location.path('/home'); } } }); }]); not sure looks good.
Comments
Post a Comment