Adoratus Adoratus - 4 years ago 100
Ajax Question

Why my resolve doesn't return data?

Hear is my route

.state('single_event',{
url: '/event/:id',
templateUrl: 'single_event.html',
controller: 'singleEvent',
resolve: {
resolvedVal: function() {
return 'Karl';
}
}

});


That it my controller

mainApp.controller('singleEvent',['$scope', function ($scope, resolvedVal) {
console.log(resolvedVal);
}]);


Why i can't get data from this resolve? I always got undefined when try to get return.

Thanks!

Answer Source

You haven't injected the resolve variable correctly. You are using 'square-brackets' notation to inject dependecies, which we use to uglify code but you are not passing resolvedVal in it. So thats why you are getting undefined.

Here's the updated code, it will work.

mainApp.controller('singleEvent',['$scope', 'resolvedVal', function ($scope, resolvedVal) {
    console.log(resolvedVal);
}]);

Let me know if it doesn't solve your issue.

For more on how to inject dependencies inside 'square-brackets' inside controllers, see this answer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download