Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Angular cli generate class, interface and enum

Suggested Videos
Part 10 - Angular cli generate service | Text | Slides
Part 11 - Angular cli generate module | Text | Slides
Part 12 - Angular cli generate directives, pipes and routing guards | Text | Slides

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

angular cli tutorial for beginners

2 comments:

  1. Hi Sir,
    I tried --flate comment to create Specifies folder, but its not working for TypeScript futures,

    ReplyDelete

It would be great if you can help share these free resources