Learn Angular 19 : Master ngOnChnage()  Life cycle hook method  | Real World Example | Episode 9

Learn Angular 19 : Master ngOnChnage() Life cycle hook method | Real World Example | Episode 9

32 Lượt nghe
Learn Angular 19 : Master ngOnChnage() Life cycle hook method | Real World Example | Episode 9
In this video, we will discuss about the ngOnChnage() life cycle hook method in angular 19 What is ngOnChanges()? Ans: ngOnChanges() is a lifecycle hook in Angular that is triggered when any data-bound input property changes. It's mainly used in child components to respond to changes in input values passed from the parent component. Summary @Input() is used to pass data from parent to child. ngOnChanges(changes: SimpleChanges) detects changes to input-bound properties. SimpleChanges contains information about the current and previous values. When is ngOnChanges() called? Only called when an @Input() property changes due to data-binding from a parent component. Not called when the child changes the value of its own input property internally. What is SimpleChanges? It’s a map of all changed inputs, where: previousValue – the old value. currentValue – the new value. firstChange() – boolean indicating if it's the first change. You can check changes['inputName'].firstChange to detect initial change. When to use ngOnChanges() instead of ngOnInit()? ngOnInit() is called once. Use it for initialization. Use ngOnChanges() when the component relies on dynamic inputs from a parent that may change over time. #angular19 #angular #angular_developer #angulartraining