Sijin T V
Sijin T V

Reputation: 329

Child state not Inheriting resolved dependencies from parent state

Here is my code

$stateProvider
        .state('admin', {
            abstract: true,
            templateUrl: "views/common/content.html",
            resolve: {
                channel: function($stateParams){
                    return $stateParams.id
                }
            }
        })
        .state('admin.dash',{
            url: "/dash",
            templateUrl: "views/admin/admin_dash.html"
       })

and i have many controllers for this admin_dash.html view using ng-controller. And in any of these controllers (child) i am not able to inject 'channel' which is the resolved dependency of the parent state, which should be inherited.

Upvotes: 1

Views: 99

Answers (1)

Shane Daniel
Shane Daniel

Reputation: 959

The resolve injectables will not be available to any old ng-controller, but only to the controller specified to the state.

E.g.

$stateProvider
    .state('admin', {
        abstract: true,
        templateUrl: "views/common/content.html",
        resolve: {
            channel: function($stateParams){
                return $stateParams.id
            }
        }
    })
    .state('admin.dash',{
        url: "/dash",
        templateUrl: "views/admin/admin_dash.html",
        // Injectable here
        controller: function(channel, $rootScope) {
            console.log('Received channel from parent resolve:', channel);
            // If need for ng-controller bound controllers...
            $rootScope.channel = channel;
        }
    })

Upvotes: 1

Related Questions