Skip to content

Cannot override nested state resolve values #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chadcallahan opened this issue Apr 10, 2013 · 4 comments
Closed

Cannot override nested state resolve values #78

chadcallahan opened this issue Apr 10, 2013 · 4 comments

Comments

@chadcallahan
Copy link

If I have my states defined as such:

$stateProvider
    .state('test', {
        url: '/test',
        controller: TestController,
        resolve: {
            testValue: function () {
                return 0;
            }
        }
    })
    .state('test.nested', {
        url: '/nested',
        resolve: {
            testValue: function () {
                return 1;
            }
        }
    })

And a controller as such:

function TestController (testValue) {
    console.log(testValue)
}

The controller always traces out a value of 0 for testValue, regardless of whether I navigate to /test or /test/nested. It seems the resolve values in nested states are not overriding the resolve values in the parent state.

@ksperling
Copy link
Contributor

Thats definitely meant to work, will have a look

@ksperling
Copy link
Contributor

Ah, just noticing that your controller is defined on the parent state. A controller is only ever going to see 'resolve' values form it's own state and their ancestors. The controller isn't re-created when a child state is entered, so it does not make sense for it to see 'resolve' values of children.

A controller defined in 'test.nested' should see 'testValue' = 1

@chadcallahan
Copy link
Author

I tried to define the same controller in the nested state, but still have the same issue. I added an onEnter function to the nested state to be sure it was hitting the nested state, and it was, but I still always get 0 returned from the testValue resolve. From what I read on the documentation, I expected the resolve to be overridden by the nested state..

"Child states inherit views (templates/controllers) and resolved dependencies from parent state(s), which they can override."

@ksperling
Copy link
Contributor

Are you sure your nested controller is actually being created? I.e. does your template for the parent state's view contain a nested ui-view tag for the nested view to be created in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants