You will have to implement a class when you want to modify the behavior or add functionality to a component in certain cases.
The implementation of life cycles such as OnInit
, implies that you must create a method called ngOnInit
in your component
export declare interface OnInit {
ngOnInit(): void;
}
In this case, ngOnInit is used to initialize its angular component, see: Angular 2 Component Constructor Vs OnInit
In terms of life cycles you have all these options: https://angular.io/guide/lifecycle-hooks#lifecycle-sequence
To know if you must implement an interface you will have to read the documentation of the functionality you are trying to add,
In the case of life cycles, implementing them is a possibility, not a requirement: https://angular.io/guide/lifecycle-hooks#interfaces-are-optional-technically