javascript - ui-router resolve showing previous resolve result on first load, sometimes not showing at all on reloads -


so have structured this.

relevant state code:

       resolve:{           projectpromise: ['$stateparams', 'projects', 'session', function($stateparams, projects, session){             projects.getproject($stateparams.id).success(function(data){               session.currentproject = data;             });            }]         } 

getproject:

  o.getproject = function(project_id, container){    return $http.get('/project/' + project_id);   }; 

inside of relevant controller:

$scope.currentproject = session.currentproject; 

and inside of relevant template:

{{currentproject.title}} 

when navigate /projects/:projectid first time, shows title of correct project. if go , navigate new project, however, still shows title of first project. when refresh shows correct title. if keep refreshing after title doesn't appear @ all. i'm sure lot of problem stems not having understanding of how structure of this, call getproject , if getproject should store result of $http.get request in container passed parameter or return have. advice @ appreciated, thanks!

you need return promise resolve function otherwise angular navigate state before promise has resolved:

   resolve:{       projectpromise: ['$stateparams', 'projects', 'session', function($stateparams, projects, session){          // add `return` statement here:         return projects.getproject($stateparams.id).success(function(data){           session.currentproject = data;         });        }]     } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -