Introducing ngOnChanges()

The ngOnChanges() method is nothing less than another life cycle hook that will trigger each time Angular sets a data-bound input property. We had to use it instead of the constructor or ngOnInit() methods for a rather obvious reason: we can't load the questions unless the parent quiz property is available, so we need to postpone the Http call until the parent component sets it. Since the quiz is also retrieved with an asynchronous Http call by the parent component, we had to find a way to tell our QuestionListComponent when the data-bound property is actually updated.

The following schema should help you better visualize the issue:

The rounded rectangle with gray background is the asynchronous thread where the ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.