angularangular-component-life-cycle

What happen if i use ngOnInit method without implementing OnInit interface


Can anyone please tell me what will happen if I don't implement onInit interface and still using ngOnInit component lifecycle inside a component?

Since I used ngOnInit lifecycle hook without implementing an interface and it's worked for me the same.

So just wanted to understand why I should implement an interface?


Solution

  • It will still work as expected.

    Interface helps us to avoid spelling and syntax mistakes.

    According to recomendations from Angular Style Guide

    Lifecycle interfaces prescribe typed method signatures. Use those signatures to flag spelling and syntax mistakes.