async / await should really be thought as a better way to use Promises reliably and safely with less chances of programming errors.
This lesson covers the fundamentals of annotating a function as async. An async
function gets the chance to use the await
keyword. This lesson covers the usages of these keywords.
I tried making a constructor function async, and typescript yelled at me. What’s the best practice when I have async operations inside of my constructor? Continue using .then(() => { … })
? Refactor the async code somewhere else?
What’s the best practice when I have async operations inside of my constructor
Add an async
init
method e.g. new Foo().init().then
and so on 🌹
This is inside of an Angular component, I don't explicitly call new Component()
, the framework does it for me. Would I put this logic inside ngOnInit?
This is inside of an Angular component, I don't explicitly call
new Component()
, the framework does it for me. Would I put this logic inside ngOnInit?
That would work. However angular will not wait for for the promise chain to complete.
Good to know