Introduction
ngOnInit helps you run code right after your Angular component is ready. It is used to set up things like data or start tasks.
You want to load data from a server when a page opens.
You need to set initial values for variables in your component.
You want to start a timer or subscribe to events when the component appears.
You want to run code only once after the component is created.