Thursday, 15 March 2012

angularjs - Not resolving a factory service with http within & ui-router before controller is called -



angularjs - Not resolving a factory service with http within & ui-router before controller is called -

i using angular.js, ui-router, userservice mill , controller.

the problem have when resolv returns in route not resolved when controller activated.

this userservice:

app.factory('userservice',["$rootscope","$q","$http","$window",function($rootscope,$q,$http,$window) { var accountinfo; homecoming { getcurrentaccount: function() { $http.get("/api/v1/accounts").then(function(data){ accountinfo=data; homecoming data; }) }

and state in route:

.state("in",{ url:"/in", templateurl: "/templates/in.html", authenticate: true, controller: "incontroller", resolve: { servicename: 'userservice', accountinfo: function(servicename) { homecoming servicename.getcurrentaccount(); } } })

on week. have done lot of reading , research. have been unable resolve this. no pun intended!

you need homecoming promise resolve function route wait until promise resolved. getcurrentaccount() should homecoming result of $http request:

getcurrentaccount: function() { homecoming $http.get("/api/v1/accounts").then(function(result){ accountinfo = result.data; homecoming result.data; }); }

angularjs angular-ui-router

No comments:

Post a Comment