Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have a set of objects that get resolved using :resolve

I also have a controller that I define by passing it the name as a string but I need to pass in the resolved objects to it.

I know it can be done like this:

resolve: { title: 'My Contacts' },
  controller: function($scope, title){
    $scope.title = 'My Contacts';
  }
}

but I need to do it like this:

resolve: { title: 'My Contacts' },
  controller: 'ResultsController'
}

How can I pass in 'title' to my controller in this sense?

Thanks, James

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Try this one out (it should work):

// State configuration...
{
  resolve: {
    title: function () {
      return 'My Contacts';
    }
  },
  controller: 'MyCtrl'  
}

// Controller

app.controller('MyCtrl', function ($scope, title) {
  $scope.title = title; 

  console.log($scope.title); // -> 'My Contacts'
});
share|improve this answer
    
Didnt see this answer :) thanks – jameslouiz Jul 27 '14 at 18:18

Pass the resolve as a function instead.

resolve: { 
    title: function() { 
      return 'My Contacts'; 
    } 
}
share|improve this answer
    
Hi, thanks but this is practically the same as above. I was looking to be able to pass title into the controller. Please see my answer below :) – jameslouiz Jul 27 '14 at 17:51

Okay, so I thought I tried this but anyway, passing it in as a dependency works:

eventaApp.controller('ResultsController', ['$scope', 'resolvedEventsData', function( $scope, resolvedEventsData ) {

    // now have access to resolvedEventsData 

}]);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.