Why bother?

Wait a minute... why did we have to pass the whole quiz object, since we're only using it to get the quiz ID? Can't we just forget about it as a whole and just pass the quiz ID from the QuizEditController? We won't need to wait for any async call, as we're already getting it from the route! Why should we complicate the task with all this ngOnChanges() fuzz?

This is a legitimate question, especially now that the app is still in its embryonic stage, we can definitely afford to have a component that will serve all the available questions for a given quiz without knowing anything about the quiz itself, other than its ID. We can even say that, for the time being, working with the quiz ID and forgetting about the rest would be the right thing to do here. However, there will be other scenarios where we will need to have more information from our source object--or from our parent component--than those we can fetch from the parent route. Sooner or later, we'll definitely hit one of them; when it happens, we'd love to know that we could do something better than just issuing another Http call and re-fetch it all from scratch.

The ngOnChanges() life cycle hook will be a powerful tool in our Angular arsenal; learning how it works and how to use it can be a great help to overcome a number of nasty concurrency issues between components and is definitely a great addition in our Angular knowledge. For further information regarding it, we strongly suggest that you refer the following URL addresses from the Angular official documentation:

https://angular.io/api/core/OnChanges
https://angular.io/guide/lifecycle-hooks#onchanges
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.249.210