AngularJS UI Router Resolve not called second time -


i using angularjs ui router resolves checking if user authentificated. called once. first works should, when try enter page again, skips resolve part , opens page.

.state('login', {     url: "/login/:state/:stateparams",     templateurl: "views/main.html",     params: {           stateparams: ""        }     }) .state('placeorder', {     url: "/placeorder",     templateurl: "views/placeorder.html",     params: {          neworder: {              from: null,              to: null,              selectedlogtype: null,              selectedlogsubtype: null          }     },     resolve: {         auth: function ($cookies, $stateparams, $location) {             if (!angular.isdefined($cookies.get('token'))) {                 $location.path('/login/placeorder/'+json.stringify($stateparams.neworder));             }             else {                 authservice.checktoken().then(function (d) {                 if (d == false) {                          $location.path('/login/placeorder/'+json.stringify($stateparams.neworder));                      }                 });             }         }     } }); 

update: have changed following, , works when there no cookie set, async function doesnt work. when logged in, doesn't work ($q.resolve part)

.state('placeorder', {     url: "/placeorder",     templateurl: "views/placeorder.html",     params: {         neworder: {             from: null,             to: null,             selectedlogtype: null,             selectedlogsubtype: null         }     },     controller: "placeorderctrl",     resolve: {         auth: function ($q, $cookies, $timeout, $stateparams, $state) {             var defer = $q.defer();             if (!angular.isdefined($cookies.get('token'))) {                 $timeout(function () {                     $state.go('/login/placeorder/'+json.stringify($stateparams.neworder));                 });                 defer.reject();             }             else {                 authservice.checktoken().then(function (d) {                     if (d == false) {                         $timeout(function () {                             $state.go('/login/placeorder/'+json.stringify($stateparams.neworder));                         });                         defer.reject();                     }                     else                     {                         defer.resolve();                     }                 });             }             return defer.promise;         }     } }) 

now doesn't resolve.

ok, found solution. anyway :)

.state('placeorder', {     url: "/placeorder",     templateurl: "views/placeorder.html",     params: {         neworder: {             from: null,             to: null,             selectedlogtype: null,             selectedlogsubtype: null         }     },     controller: "placeorderctrl",     resolve: {         auth: function ($q, $cookies, $timeout, $stateparams, $state, authservice) {             var defer = $q.defer();             if (!angular.isdefined($cookies.get('token'))) {                 $timeout(function () {                     $state.go('/login/placeorder/'+json.stringify($stateparams.neworder));                 });                 defer.reject();             }             else {                 authservice.checktoken().then(function (d) {                     if (d == false) {                         $timeout(function () {                             $state.go('/login/placeorder/'+json.stringify($stateparams.neworder));                         });                         defer.reject();                     }                     else                     {                         defer.resolve();                     }                 });             }             return defer.promise;         }     } }) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -