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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -