Justin Young Justin Young - 1 year ago 78
AngularJS Question

resolve resource in route

Trying to send my resolved data to my controller. Things resolve fine, just can't figure out how to pass it into my controller. Right now I get get undefined when I try and log out the resolved data.

My module:

function($stateProvider) {
.state('view', {
url: '/:projectId',
templateUrl: 'view.html',
projectaa:function(apiResource, $stateParams){
apiResource.get({api_resource:'projects', api_value:$stateParams.projectId}).$promise.then(function(response){
return response;


angular.module('projects').controller('ProjectsClientController', ['$scope', '$stateParams', 'projectaa',
function($scope, $stateParams, projectaa) {


What am I doing wrong?

Answer Source

It should also return the promise of apiResource.get so that the promise chain .then function would be accessible inside the controller


projectaa: function(apiResource, $stateParams) {
    return apiResource.get({
        api_resource: 'projects',
        api_value: $stateParams.projectId

Inside controller you could get data by resolving that promise using .then


   console.log(data); //you will get promise resolved here
   //which will return data here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download