2

I'm following the instructions on the ui-router wiki which relates to working with resolves. If I follow the instructions on the wiki I get the value shared in to the controller without an issue, if I include the controller by reference the value is undefined. What am i missing?

.state('intro', {
            url: '/',
            resolve:{
                resA:  function(){
                    return {'value': 'A'};
                }
            },
        views: {
            'content': {
                templateUrl: 'views/home.html',
                controller: function($scope, resA){
                  $scope.resA = resA.value;
                }
            },
            'navigation': {
                templateUrl: 'views/navigation.html'

            }

        } })

    .controller('introController', ['$scope', function($scope,resA) {
    $scope.resA = resA.value; //undefined

2 Answers 2

5

This is because you did not include resA in your array notation, it should be like this:

.controller('introController', ['$scope', 'resA', function($scope, resA) {
    $scope.resA = resA.value;
}]);
Sign up to request clarification or add additional context in comments.

Comments

1

There is a working example

We have to declare this controller, e.g. as a part of state def:

'navigation': {
     template: '<div>navi - resA: {{resA}}</div>',
     controller: 'introController',
},

then we have to properly pass arguments (the 'resA' must be passed as well)

 .controller('introController', ['$scope', 'resA'
 , function($scope,resA) {
    $scope.resA = resA.value; //undefined
 }])
;

Working plunker

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.