I'm going through the AngularUI Router sample app in http://angular-ui.github.io/ui-router/sample/#/
I think I understand in general what is going on and have been able to implement something similar for my app.
My question is that it seems that you can access $stateParams
from "View" files (e.g. https://github.com/angular-ui/ui-router/blob/master/sample/contacts.html - where it refers to $stateParam
), but when I access the $stateParams
in the controller, it returns an empty object. (https://github.com/angular-ui/ui-router/blob/master/sample/states.js#L83)
So I guess what I'm trying to do is access the state of the child view in the parent view controller via $stateParam
s, but it's an empty object.
Instead, I can get the state by doing $state.params.PARAMETER_NAME
.
Why is that?
This is by design, see https://github.com/angular-ui/ui-router/wiki/URL-Routing#two-important-stateparams-gotchas
It seems like a good idea to me, it's not very clear code if you're accessing state params from a child view in one of its ancestors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With