javascript - Angular stateprovider resolve not passing data to controller -
so have problem angular ui.router, apparently isn't passing data resolve controller. have following state set up:
$stateprovider .state('mystate', { url: "/myurl", templateurl: "mytemplate", controller: 'mycontroller', resolve: { randomdata: function($q, $sails) { var defer = $q.defer(); $sails.get("/me") .success(function(data) { console.log(data) // prints out actual data defer.resolve(data); }) return defer.promise; } }
and in mycontroller
have
myapp.controller('mycontroller', [ '$scope', function ($scope, randomdata) { console.log("randomdata:" + randomdata) // prints out 'randomdata: undefined' } ])
according every doc, stackoverflow post , tutorial, piece of code should work, keeps printing undefined. have idea why isn't working?
you forgot inject data in array notation:
myapp.controller('mycontroller', [ '$scope', 'randomdata', // <-- 1 function ($scope, randomdata) { console.log("randomdata:" + randomdata); } ])
Comments
Post a Comment