angular generate class code example

Example 1: angular generat model

ng generate class hero --type=model

Example 2: create class angular

// to create a model class, we first need to create a new file
//f.e person.ts

export class Person {
 constructor(
  public name: string,
   public lastName: string,
   public age:number
  
  ) {}
}

//now that we have the model class we can create arrays that contain Person class elements

.
.
public people: Person[];
constructor(){
 this.people = [
   new Person ('Carla','Smith', 20 ),
    new Person ('Carlos','Smith', 25 ),
    new Person ('Andrea','Johnson', 23 ),
   
   ];
}

Example 3: ng generate component

ng g component [component name]

Example 4: angular cli skip-tests

The name of the TypeScript configuration file for tests. Default: ... --skipTests=true|false. When true, does not create "spec.ts" test files for the app. Default: false

While generating component using cmd
>ng g c component-name --skipTests

Example 5: ng g

ng g directive <name> [options]