Comments (7)
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.
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.
Sorry should have also mentioned that you should be able to use $state.$current.params in resolve instead, let me know.
from ui-router.
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.
@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.
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.
$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)
- Resolve triggering twice HOT 1
- No services listed in 2.x docs HOT 2
- Optional params included on all similar routes HOT 1
- child states of lazy loaded future states get stuck in stateQueue HOT 1
- Transition Rejection : while upgrading angularjs from 1.5 to 1.8 using angular-route:1.0.0 HOT 1
- this.parent.parameters() is not a function while Upgrading angular-ui-router from 0.2.15 to 1.0.29
- I used transition.onStart() instead of stateChangeStart, but it shows .onStart is not a function.
- Documentation Broken HOT 1
- Access states' custom data-object in component
- dependency's version is not the same
- Update @uirouter/core dependency to 6.0.9 HOT 3
- Support for Standalone components HOT 1
- Is this library still being maintained? HOT 1
- V1.1.0 - TypeError: Cannot read properties of undefined (reading 'inherit') HOT 36
- AngularJS v1.3.5 - Page reloads on route change after npm install for latest build.
- Angular: StateService injected in custom library results in R3InjectorError HOT 1
- ui-router
- https://github.com/angular-ui/ui-router/tree/e8694114594d5aaf9f40e27b8ba194bca85595de
- str.split is nto a function HOT 1
- Please release the 1.1.0 version as soon as possible. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ui-router.