When I use the function ngOnInit, TS lint warned me I should add implements OnInit. But I can use the function ngOnInit normally without implementing OnInit. What's the difference between the two ways?
When I use the function ngOnInit, TS lint warned me I should add implements OnInit. But I can use the function ngOnInit normally without implementing OnInit. What's the difference between the two ways?
I assume you are using Typescript
You don't have to add implements OnInit as this is TypeScript and JavaScript does not have a concept of Interfaces. So when you implement an interface, this does not actually exist at run time.
Implementing an interface gives you all the strong type checking, and the TSC will throw out any warnings.
So, I do recommend you still to use the interface for this reason, plus it's a good practice.
There is no difference. It's only good style to add implements OnInit.
ngOnInit is the only method this interface requires.
There is literally no difference between the two if you are talking about the "compiled" version (after TypeScript processed to runnable JavaScript). The Interface will just be removed (there are no TypeScript Interfaces at runtime). Except, the only real difference is that some Angular Tooling could make use of that information (static analysis, etc). However if you do not use any Tooling this information is just for yourself, respectively for all coders of the project. You could easily remove that rule from your tslint config and everything would keep working the same way.