Use “DoCheck” to catch all changes that happen in the Angular Component.
I'm writing this because there might be someone whos not aware of this and need this function to do the things that they want in angular. How Ever you might know this function and used it before so, this blog is not for you.
As the title says if you are trying to run a method or do something in the angular component whenever there is a change happened in the component you can use the ngDoCheck() function.
So let’s see what is this and what can we do in this function that.
“DoCheck function is used to catch any changes within the angular component that cant be caught in any other way. so basically this “ngDoCheck()” function will run every time there is any kind of changes happen in the Angular Component. it will run when a variable value is changed that basic things also can be captured from this function.
as you all know as angular developers we can use this function as we using the “ngOnInit()” and “ngOnChange()”.
So in this method, we are handling all the kinds of stuff with if-else statements. because the function will run every time there is a change in the component so here some example code that you can check.
As you can see this is how simple that is. you can use this “ngOnChange()” function to do lots of things in angular developing.
Hope you learned something.
Happy coding 😊 ❤