angular generate module code example

Example 1: generate module with routing in angular

ng g m [ModuleName] --routing

Example 2: angular generate component

ng g component componentname

Example 3: angular cli generate new module

ng generate module module-name

Example 4: angular cli generate component

ng g c componentName

Example 5: ng new module w route

// Use this command to create a  lazy-loaded feature module with routing, along with its stub component.

ng generate module <MODULE_NAME> --route <ROUTE> --module app.module

Example 6: 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 ),
   
   ];
}

Tags:

Misc Example