Hello Devs,

In this tutorial, we are going to learn how to generate component in angular 10.

When you are creating component using angular cli command then they will create new folder with four files and also they will register in moduler.ts file.

Follow this step by step guide given below:




Create New App:

ng new RathorjiApp
ng g c favorite

app/favorite/favorite.component.html

<p>favorite works!</p>

app/favorite/favorite.component.css

p{ color:red }

app/favorite/favorite.component.ts

import { Component, OnInit } from '@angular/core';

   

@Component({

  selector: 'app-favorite',

  templateUrl: './favorite.component.html',

  styleUrls: ['./favorite.component.css']

})

export class FavoriteComponent implements OnInit {

  

  constructor() { }

  

  ngOnInit() {

  }

   

}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { FavoriteComponent } from './favorite/favorite.component';

@NgModule({

  declarations: [

    AppComponent,

    FavoriteComponent

  ],

  imports: [

    BrowserModule

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule { }


Run these commands:

<app-favorite></app-favorite>
ng g c admin/users


I hope this example helps you.