29
loading...
This website collects cookies to deliver better user experience
home.component.ts
and a html file named home.component.html
under the home folder (just created)home.component.ts
fileimport { Component } from "@angular/core";
@Component({
selector: 'my-home',
templateUrl: './home.component.html'
})
export class HomeComponent { }
home.component.html
file<h2>My First Component</h2>
app.module.ts
(this module is provided by the Angular team along with the first component).declarations
array marked with yellow arrow.HomeComponent
!!!AppComponent
and write HomeComponent
. You might get a red squiggly line like below - import
. Like that you need to add another line after AppComponent
providing the HomeComponent path, like below -import { HomeComponent } from './home/home.component';
app.component.html
<my-home></my-home>
ng generate component <component-name>
EG. ng generate component my-second-home
and hit enter. Also there is another shorter command. It is ng g c <component-name>
where g stands for generate and c stands for component. Once you hit enter Angular will create four filesimport { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-second-home',
templateUrl: './my-second-home.component.html',
styleUrls: ['./my-second-home.component.css']
})
export class MySecondHomeComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
<app-my-second-home></app-my-second-home>