You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Route resolve provider functions that are making a request on server are loading and making the request at the same time. It is a normal behavior but there is a situation when one resolve result depends on another, more like promises.
Expected behavior
In Angular.js, using the ui-router, i could inject into a route resolve function an already resolved one. I will put an example code here:
As you can see i can use the X result in Y.
The thing is that in order to do this in Angular i have to use the ngOnInit function, get the resolved function from a parent route or to make a resolve provider that makes a server request and then does the other. These solutions make the code look bad and i would like to know if there is a solution for this.
So, from my experience and knowledge, in Angular i can't inject the result of a previous route resolve like in Angular.js ui-router because i'm forced to provide a class implementing the Resolve Interface that has a function where i can't access previous resolved parameters.
To make the question even more clear. i will add 2 more pics with an example of Angular code:
What is the motivation / use case for changing the behavior?
There are rare cases where one route resolve provider depends on another.
Thanks for your answer @noamichael . In the end i had to choose for this specific problem between your answer, ngOnInit and Guards. I requested this feature because it would be useful to separate requests in order to have a better organised code.
This is someting that should have real priority. I wouldn't say these cases are rare, they are actually quite common when someone is implementing anything more serious than merely just example todo lists.
It would be nice if at least parent resolvers were run before child guards. If this doesn't work, working with real-world data flows and more complicated tasks quickly becomes big pain in the ass.
This is not something we are looking at implementing at this time. I think we got used to this behavior with ui-router in AngularJS, but that worked due to a different type of dependency injection.
A better pattern would be to use something other than Resolve to get your data. Use a service that manages the dependencies. This will be much more testable.
Additionally, we would like to look at passing Observables in through something like a Resolve, but instead of the current implementation you would be able to combine them together and they wouldn't need to be completed like Resolve currently does.
Activity
noamichael commentedon Sep 8, 2017
Could you use one resolver with a promise chain?
dragospeta commentedon Sep 8, 2017
Thanks for your answer @noamichael . In the end i had to choose for this specific problem between your answer, ngOnInit and Guards. I requested this feature because it would be useful to separate requests in order to have a better organised code.
xaralis commentedon Dec 5, 2017
This is someting that should have real priority. I wouldn't say these cases are rare, they are actually quite common when someone is implementing anything more serious than merely just example todo lists.
It would be nice if at least parent resolvers were run before child guards. If this doesn't work, working with real-world data flows and more complicated tasks quickly becomes big pain in the ass.
jasonaden commentedon Dec 7, 2017
This is not something we are looking at implementing at this time. I think we got used to this behavior with ui-router in AngularJS, but that worked due to a different type of dependency injection.
A better pattern would be to use something other than Resolve to get your data. Use a service that manages the dependencies. This will be much more testable.
Additionally, we would like to look at passing Observables in through something like a Resolve, but instead of the current implementation you would be able to combine them together and they wouldn't need to be completed like Resolve currently does.
angular-automatic-lock-bot commentedon Sep 12, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.