I have a component with some lifecycle hooks.
By synchronous I mean the execution of hooks one after another.
export class MyComponent implements OnInit, OnChanges, AfterContentInit, AfterViewInit {
ngOnInit() {
console.log('ngOnInit');
setTimeout(() => {
console.log('setTimeout');
});
}
ngOnChanges(changes: SimpleChanges): void {
console.log('ngOnChanges');
}
ngAfterContentInit(): void {
console.log('ngAfterContentInit');
}
ngAfterViewInit(): void {
console.log('ngAfterViewInit');
}
}
There are two cases
They are Synchronous - Then setTimeout call at the end is justified by itself. But can someone please point me any Angular documentation or Angular code to support it.
If not - Can anyone help me understand why setTimeout is running at the end.
I know how event loop works and that life cycle hooks run in sequence, but my question is how Angular achieves it? when I look at the call stack in chrome debugging mode, I don't find any sequence.
Is it guaranteed that setTimeout in the above example will run after all the above hooks?