Using ngOnChanges to intercept input property changes
In this recipe, you'll learn how to use ngOnChanges to intercept changes using the SimpleChanges API. We'll listen to a vName input passed from the VersionControlComponent parent component to the VcLogsComponent child component.
Getting ready
The project for this recipe resides in chapter01/start_here/cc-ng-on-changes:
- Open the project in Visual Studio Code.
- Open the terminal and run
npm installto install the dependencies of the project. - Once done, run
ng serve -o. This should open the app in a new browser tab and you should see the app as follows:
Figure 1.7 – The cc-ng-on-changes app running on http://localhost:4200
How to do it…
- We'll first create a logs array in
VcLogsComponentas follows to store all the logs that we'll display later using our template:export class VcLogsComponent implements OnInit { Â Â @Input() vName...