2

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

3 Answers 3

5

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'
});
Sign up to request clarification or add additional context in comments.

Comments

0

Pass the resolve as a function instead.

resolve: { 
    title: function() { 
      return 'My Contacts'; 
    } 
}

1 Comment

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 :)
0

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 

}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.