-
Notifications
You must be signed in to change notification settings - Fork 25.3k
-
Notifications
You must be signed in to change notification settings - Fork 25.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
async lifecycle hooks - should angular support 'await ngOnInit' or other hooks #17420
Comments
This seems like an awkward way of executing something in a microtask. How often are you seeing this? |
The way people seem to think of it is as a neater way of getting your initial data before the component gets loaded. So instead of using Promise/Observable they revert to async. It seems an easy mistake to make as you when you put It's a bit difficult to say how often but it is there on the web I think the main place people would think of using it is |
I am not sure that an explicit warning about this is needed as it doesn't interfere with Angular's lifecycle hooks. It is equivalent to saying something like. ngOnInit() {
Promise.resolved().then(() => ...);
} which executes the lambda in its own microtask. |
@alex321 do you see this as something that works more like |
@chuckjaz Not quite as it pauses @robwormald That is how I interpreted my teammate's intention. It looked like another way of using I just wanted to raise it as a question to understand whether it will cause problems now or in the future. I personally don't love it as:
I can see now that the hooks are just triggers and that angular doesn't care what happens afterwards but it does feel like a poor coding practice unless we wait |
@alex321 Can you rewrite issue description above to make it clear what you are recommending? |
@chuckjaz I am quite happy to close this one to be honest as judging from your answers, it's not a problem for someone to use I am not sure whether there is any value in making |
@alex321 Thanks! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Hey, I would be interested whether it makes sense to support adding
async
in front of the Angular lifecycle hooks e.g.async ngOnInit() { await ... }
I saw that being used recently and I immediately sounded an alarm as this would prevent the correct ordering of lifecycle hooks. IMHO I can see why the person used it but I am not sure that it makes sense for Angular to provide that.
Would it make sense to put any warnings in the docs? Thanks!
The text was updated successfully, but these errors were encountered: