-
Notifications
You must be signed in to change notification settings - Fork 3k
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
$stateParams vs $transition$.params() #3237
Comments
Related question (that might get answered by answering @jwickens' question about the difference between those two): What is the best practice to access parameters inside Services? Sometimes, I find it very cumbersome to obtain Is |
Yes, since
The difference is documented in the migration guide and in the The |
The
(This is the same as injecting |
I am trying to use I am using typescript with angular 1 and a webpack build with ng-annotate, my constructor code is below:
|
@theatrain check out https://ui-router.github.io/guide/ng1/route-to-component#accessing-transition |
Perfect, that works. Thanks! |
@christopherthielen , I think I'm having a similar problem where I need a $stateParams reset for parent state when sharing a single controller in child states: If you could advise as I've researched the hell out of it and running out of ideas! |
@harrylincoln did you come up with something? |
Yes I did! Workaround that's a little messy but safe. I basically introduced an 'init' state that inits the detail states and have the parent just handle basic html templating stuff. I answered my own question on stackoverflow: |
@christopherthielen was there any change to this? I'm using the legacy |
@samiraguiar this may help: |
@harrylincoln Thanks, Harry, but I think my problem is different. angular.module('app').directive('myDirective', function($transition$) {}); And my route defined as follows: {
name: 'someRoute',
url: '/path/to/route',
template: '<my-directive></my-directive>'
} But this gives me the "Unknown provider: $transition$Provider <- Here's a plunker showing the problem. What am I doing wrong? |
@samiraguiar pretty sure you've missed a step there. Your routing won't have access to your directives since it's bound to the app.config which (I believe) is instantiated before your directives/controllers. Basically this won't work:
You need something like this:
This is all in the ui router docs |
@harrylincoln Thanks, Harry. Indeed, apparently Got it working by changing my directive code to: angular.module('app').directive('myDirective', function($scope) {
var id = $scope.$resolve.$transition$.param().id;
}); Though I don't find it pretty. |
Makes sense. There are many ways to skin a cat in Angular ;) |
If you are routing to a directive template, bind the transition object as an attribute like so:
If you are using route-to-component, you can use an input binding
then route to component:
|
This issue has been automatically marked as stale because it has not had This does not mean that the issue is invalid. Valid issues Thank you for your contributions. |
I was following https://ui-router.github.io/tutorial/ng1/hellosolarsystem and trying to get state params working. However, on trying to load a state with a resolve using$transition$ there was an unlogged error and nothing loaded.
I found in the hello universe docs @stateParams and that works fine.
What is the difference or do the docs need updating?
The text was updated successfully, but these errors were encountered: