Introducing the component lifecycle
Life cycle events are hooks that allow us to spy on specific stages in the lifecycle of a component and apply custom logic. They are entirely optional to use but might be of valuable help if you understand how to use them. Some hooks are considered best practice to use, while others help with debugging and understanding what happens in an Angular app. A hook comes with an interface
that defines a method that we need to implement. The Angular framework makes sure the hook is called, provided we have implemented this method in the component. It is not obligatory to define the interface
in the component, but it is considered a good practice. The Angular framework cares whether we have implemented the actual method or not. The available component lifecycle hooks are as follows:
OnInit
OnDestroy
OnChanges
DoCheck
AfterContentInit
AfterContentChecked
AfterViewInit
AfterViewChecked
All of the previous lifecycle...