HI WELCOME TO SIRIS

Angular cli generate class, interface and enum

Leave a Comment

So far we have discussed generating angular features like components, services, directives etc. We can use the Angular CLI to generate TypeScript features as well. In this video we will discuss generating TypeScript features like classes, interfaces and enumerations using the Angular CLI.


As you have seen throughout this course, Angular CLI provides consistent set of commands for generating features. 

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

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.