组件是Angular中的主要构建块,Angular框架允许用基于组件的方法开发应用程序。
如何在Angular中创建组件
最简单,最快的创建组件是使用Angular CLI,要生成hello-world组件,我们需要运行以下命令:ng new generate component
@Component装饰器
@Component是一个注释,它告诉Angular,把class/template/style附加到特定组件,@Component修饰符用于定义关联的元数据,
import { Component } from '@angular/core';
@Component({
selector: 'app-hello-world',
templateUrl: './helloWorld.component.html',
styleUrls: ['./helloWorld.component.css']
})
export class HelloWorldComponent {
// Properties & methods
}
相关文章