Complete Guide: Angular lifecycle hooks #248
Replies: 6 comments 1 reply
-
It's a wonderful guide. very well explained. Thank you do much, it made my life really easy to some extent. |
Beta Was this translation helpful? Give feedback.
-
HTML chunk of code is missing at code example from Missing part: // parent.component.html
<button (click)="updateUser()">Update</button>
<app-child [userName]="userName"></app-child> |
Beta Was this translation helpful? Give feedback.
-
Very well explained. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the thorough explanation, I have a question, does any of these hooks change when ChangeDetectionStrategy.OnPush is set? |
Beta Was this translation helpful? Give feedback.
-
Hi There is a typo here. // components/child/child.component.ts export class ChildComponent implements OnChanges{
@Input() userName = '';
ngOnChanges(changes:SimpleChanges) {
console.log('ngOnChanges triggered', changes);
if (!changes['userName'].isFirstChange()){
if (changes['userName'].currentValue === "Chris") {
this.userName = 'Hello ' + this.userName
} else {
this.userName = changes['userName'].previousValue
}
}
}
} It should be |
Beta Was this translation helpful? Give feedback.
-
Very good, it's possible to add setter and getters to the lifecycle? like the constructor they are not part of the lifecycle but can help to understand the order and afectation of the inputs |
Beta Was this translation helpful? Give feedback.
-
Discussion for "Complete Guide: Angular lifecycle hooks" article
Beta Was this translation helpful? Give feedback.
All reactions