How to Create New Component in Angular 8?

How to Create New Component in Angular 8?

tutorials -

Today, i will show you how to generate component in angular 8 app using cli command. we will create component using ng generate command in angular 8. so you will understand to angular 8 ng generate component command.

So, basically, 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.

In this example, we will run command and let's see which files created and what you have to write on that file code. You can easily understand to generate new component in angular 8 application.

Create New App:

If you want to test it from scratch how to generate component in angular app then you can run following command to download new app:

ng new ItSolutionStuffApp

Now in that app you can generate new component using following command:

ng g c favorite

Now you can see it will be generate new files as like bellow screen shot:

Now it's generate new component in angular 8 app. You can see affected on following files:


You can write HTML code:

<p>favorite works!</p>


You can write CSS code:

p{ color:red }


You can write Core Logic code:

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


selector: 'app-favorite',

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

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


export class FavoriteComponent implements OnInit {

constructor() { }

ngOnInit() {




import { async, ComponentFixture, TestBed } from '@angular/core/testing';

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

describe('FavoriteComponent', () => {

let component: FavoriteComponent;

let fixture: ComponentFixture;

beforeEach(async(() => {


declarations: [ FavoriteComponent ]




beforeEach(() => {

fixture = TestBed.createComponent(FavoriteComponent);

component = fixture.componentInstance;



it('should create', () => {




Ok, now you can understand what you have to write on which files.

You can also generate new component in inside some directory. You can try bellow command:

ng g c admin/users

I hope it can help you...

Trending On Tutorial Stuff

Our Sponsors

Top Applications in Tutorial Stuff

Top Experts In Tutorial Stuff