create folder for your component: /src/app/yourComponent
create ts and html file: /src/app/yourComponent/name.component.ts & name.component.html
edit name.component.ts
//add component function
import {Component} from '@angular/core';
//config this component for angular@Component({
selector: 'app-name', //html tag <app-name></app-name>
selector: '[app-name]' //attribute <div app-name></div>
selector: '.app-name' //class <div class="app-name"></div>
templateUrl: './name.component.html', //external html file
template: '<h1>hello</h1>', //or use inline html
styleUrls: '['./name.component.css']', //externam css file
styles: ['p{color: darkblue}'], //inline style
})
//normal typescript classexport class NameComponent{
}
edit /src/app/app.module.ts
//tell typescript where to find it, no need for .ts extendsion
import { NameComponent } from './yourComponent/name.component';
@NgModule({
declarations: [
AppComponent,
//tell angular we have a new component to use NameComponent
],