GithubHelp home page GithubHelp logo

Comments (7)

timkindberg avatar timkindberg commented on August 24, 2024

Probably a bug, @ksperling may have to look at it (he just had a kid). It does make sense that $stateParams would be available in resolve.

from ui-router.

timkindberg avatar timkindberg commented on August 24, 2024

Actually, did some research on this. In the current $route service in angular, $routeParams is not ready yet in resolve either. So it may be a technical limitation that we can't get around, we will look into though.

Check out this video: http://www.youtube.com/watch?v=P6KITGRQujQ, right around 3:45 he says it...

from ui-router.

timkindberg avatar timkindberg commented on August 24, 2024

Sorry should have also mentioned that you should be able to use $state.$current.params in resolve instead, let me know.

from ui-router.

ksperling avatar ksperling commented on August 24, 2024

Hm, its meant to work like that... $stateParams should be part of the 'locals' passed to $injector when any calls related to 'resolve' or onEnter are made. Ill look at it when I get a chance.

What currently doesn't work and isn't meant to work is injecting $stateParams into a service and using that during resolve... it seems that kind of usage would be bound to have unintended or at least unintuitive results in some use cases no matter when the global $stateParams get written, so it seems best to discourage (or even disallow?) such usage.

Rob Schley [email protected] wrote:

I've been experimenting with the new routing code and I've managed to get pretty far in converting an existing application to use the new code but I've run into a bit of a problem and I'm not sure if it is because I am doing something wrong or if it is a bug.

The issue is that $stateParams nor anything that I can see in $state has the URL parameters for the view that is being transitioned to when attempting to resolve a nested view. You can see this issue in the example application and I created a branch that demonstrates it here: https://github.com/robschley/router/blob/stateParams/sample/index.html#L115

The contacts.detail view defines dependencies to resolve before initializing the controller. To effectively resolve those dependencies, one would expect that $stateParams or $state would provide the URL parameters for the view that is being transitioned to. In this case, contactId should be available in $stateParams. When resolving "something" in the sample, there seems to be no way to get to the contactId because it is not populated into $stateParams until AFTER all of the dependencies have been resolved.

Is this a bug or am I doing it wrong? Any guidance is much appreciated.


Reply to this email directly or view it on GitHub:
https://github.com/angular-ui/router/issues/31

from ui-router.

robschley avatar robschley commented on August 24, 2024

@timkindberg Unfortunately, $state.$current.params does not contain the parameters either. I dug into $state and $state.$current quite a bit but wasn't able to find anything with the parameters for the transitioning to view.

The code that I am converting originally used $route.$current.params.

from ui-router.

juanpujol avatar juanpujol commented on August 24, 2024

Sorry to open this again, but I'm trying to get $stateParams inside a factory that I'll resolve and it just returns an empty object. What's funny is that if I do console.log($state) on the Service resolving I can see the content of $state.params witch is { id: "123" } but if I try to console.log($state.params) it returns empty object. This's very frustrating =S.

Anyone can help me?

Thanks.

from ui-router.

ksperling avatar ksperling commented on August 24, 2024

$stateParams is special in that if you get it injected globally, it will only contain the parameters for the current state once the transition into that state is complete.

To access the parameters of the state being transitioned to, you have to get $stateParams injected by 'resolve' or the state onEnter event, because $stateParams is special-cased in those injections.

from ui-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.