Angular - 5.14-Understanding the component life cycle
The first phase, the first hook that we can connect to is ngOnChanges. And it can actually run multiple times. It is executed from the outset, when a new component is created. But then it is also always called, whenever one of our related input properties changes. And by that I mean properties decorated with "@input", so whenever these properties get new values. Now the second check mark is ngOnInit. This method is executed once the component has been initialized. That doesn’t mean we can see it. It has not yet been added to the DOM, so to speak, it has not yet been displayed, but Angular has completed the basic initialization. Our properties can now be accessed and initialized, for example. So we could say that the object was created, and if you’re interested, ngOnInit will run after the builder.
Next, we have ngDoCheck. This will also be executed several times, because it will be executed every time change detection is performed. Now, change detection is simply the system by which Angular determines whether something has changed on the model of a component, or inside a component, I should say. So, if a property value changes from one to two, for example, and the output of that property is in the model. Well Angular has to rerendre this part of the pattern. And ngDoCheck is a checkmark that is executed every time Angular checks. Now, this is important at every audit. So not just if something has changed. Many times, ngDoCheck will run because you clicked on a button, which doesn’t change anything, but it’s still an event, and on events, Angular has to check if there has been a change, because otherwise how would he know? It must therefore check certain triggering events, such as when you click.
It is important that your computer is protected from malware. For this, you can use an antivirus program to detect and remove potential threats. However, for your antivirus to be effective, it must check for certain triggering events, such as when you click on a link or download a file. It is therefore important to configure your antivirus program so that it is always running and up to date to ensure the best possible protection.