What happen if i use ngOnInit method without implementing OnInit interface
Asked Answered
B

1

7

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?

Bab answered 9/5, 2020 at 18:20 Comment(0)
F
12

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.

Franciscafranciscan answered 9/5, 2020 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.