Sunday, 3 November 2019

How to generate a class, interface and enum using angular CLI?


To generate a class, use
ng generate class className
or 
ng g cl className

For example, to generate an employee class use
ng g cl employee

The above command places the employee class directly in the "app" folder. Instead if you want the employee class in a different folder, simply prefix the name of the folder. The command below creates a folder with name "employee" and then creates the "employee" class in it.

ng g cl employee/employee

By default, a spec file is not created for the class. If you want a spec file to be generated set --spec option to true.

ng g cl employee/employee --spec=true

To generate an interface use

ng generate interface interfaceName
or 
ng g i interfaceName

To generate an enum use

ng generate enum enumName
or 
ng g e enumName

No comments:

Post a Comment