angularconstructorangular9

Angular - Do We Need A Constructor If It Doesn't Have Any Logic


I'm working with Angular.

I'm wondering about whether constructors are needed, and would appreciate some insight. In several classes, I have constructor that are empty most of the time my service classes have empty constructors.

Can these empty constructors be removed? Are there any negative impact to a class have no constructor vs having an empty one?


Solution

  • If you don't use DI (dependency injection) service for Angular in your class you can remove it .

    If the class won't be used by third parties and you don't need an overloaded constructor, don't write an empty constructor.