filmov
tv
Angular Life Cycle Hook #Part2 | ngOnChanges vs ngDoCheck | (Tutorial 42)

Показать описание
Hello Everyone
This is part-2 on Angular Life Cycle Hook and will talk about ngOnChanges and ngDoCheck Life Cycle hook in details.
Support my channel by like, share and subscribe so that I can reach to wider audience and can help them :) :)
Checkout Life Cycle hook Part-1:
ngOnChanges:
This method is called once on component’s creation and then every time changes are detected in one of the component’s input properties.
It receives a SimpleChanges object as a parameter, which contains information regarding which of the input properties has changed - in case we have more than one - and its current and previous values.
This is one of the lifecycle hooks which can come in handy in multiple use cases. It is very useful if you need to handle any specific logic in the component based on the received input property
ngOnChanges() will fire before ngOnInit() and every time parentData updated from its parent component
When should you use ngOnChanges?
Use ngOnChanges whenever you want to detect changes from a variable decorated by @Input. Remember that only changes from the parent component will trigger this function.
Also remember that changes from the parent still update the child value even without implementing ngOnChanges. ngOnChanges simply adds the benefit of tracking those changes with previous and current value.
ngOnChanges change detection
ngOnChanges is triggered every time when the Angular detected a change to the data-bound input property
We also looked at how OnChanges does not fire when the input property is an array/object because Angular uses dirty checking to compare the properties.
In such a scenario, where Angular fails to detect the changes to the input property, the DoCheck allows us to implement our custom change detection.
ngDoCheck
Detect and act upon changes that Angular can’t or won’t detect on its own.
Called during every change detection run, immediately after ngOnChanges() and ngOnInit().
I believe you will like this video, Please comment , like and share this video :)
Checkout other important topics :
#angular #angularTutorial #nishasingla
This is part-2 on Angular Life Cycle Hook and will talk about ngOnChanges and ngDoCheck Life Cycle hook in details.
Support my channel by like, share and subscribe so that I can reach to wider audience and can help them :) :)
Checkout Life Cycle hook Part-1:
ngOnChanges:
This method is called once on component’s creation and then every time changes are detected in one of the component’s input properties.
It receives a SimpleChanges object as a parameter, which contains information regarding which of the input properties has changed - in case we have more than one - and its current and previous values.
This is one of the lifecycle hooks which can come in handy in multiple use cases. It is very useful if you need to handle any specific logic in the component based on the received input property
ngOnChanges() will fire before ngOnInit() and every time parentData updated from its parent component
When should you use ngOnChanges?
Use ngOnChanges whenever you want to detect changes from a variable decorated by @Input. Remember that only changes from the parent component will trigger this function.
Also remember that changes from the parent still update the child value even without implementing ngOnChanges. ngOnChanges simply adds the benefit of tracking those changes with previous and current value.
ngOnChanges change detection
ngOnChanges is triggered every time when the Angular detected a change to the data-bound input property
We also looked at how OnChanges does not fire when the input property is an array/object because Angular uses dirty checking to compare the properties.
In such a scenario, where Angular fails to detect the changes to the input property, the DoCheck allows us to implement our custom change detection.
ngDoCheck
Detect and act upon changes that Angular can’t or won’t detect on its own.
Called during every change detection run, immediately after ngOnChanges() and ngOnInit().
I believe you will like this video, Please comment , like and share this video :)
Checkout other important topics :
#angular #angularTutorial #nishasingla
Комментарии