Angular 创建组件

时间:2023-03-09 23:23:53
Angular 创建组件

创建组件

  1. 定义hello.component.ts组件
  2. app.module.ts中引用并添加到declarations声明中
  3. app.component.html中使用组件<app-hello></app-hello>

命令创建

  1. 安装Angular 5 Snippets,输入命令ng-component自动生成组件结构
  2. 使用ng命令自动创建模块: ng generate component component-name
  3. 组件会自动加入到declarations声明中