用 ng generate hello-world 命令生成 hello-world 組件
在hello-world.component.ts中定義組件
代碼貼在文章末尾:代碼1
在app.component.html中使用剛定義好的組件(標籤)
代碼貼在文章末尾:代碼2
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-hello-world',
template:
`<p>
hello-world works!
</p>
`
})
export class HelloWorldComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}