生成命令用法
你可以使用 ng generate
或 ng g
命令生成 Angular 构建块(组件,服务,管道等)。
你可以在下表中找到所有可能的蓝图 :
Scaffolding |
用法 | 缩短 |
---|---|---|
component |
ng generate component component-name |
ng g c component-name |
directive |
ng generate directive directive-name |
ng g d directive-name |
pipe |
ng generate pipe pipe-name |
ng g p pipe-name |
service |
ng generate service service-name |
ng g s service-name |
class |
ng generate class class-name |
ng g cl class-name |
guard |
ng generate guard guard-name |
ng g g guard-name |
interface |
ng generate interface interface-name |
ng g i interface-name |
enum |
ng generate enum enum-name |
ng g e enum-name |
module |
ng generate module module-name |
ng g m module-name |
所以,例如,如果你运行 ng generate component user-list
- angular-cli 将:
- 在
src/app
文件夹或运行该命令的文件夹中创建user-list
目录。 - 在该目录中生成 4 个文件(
user-list.component.ts
,user-list.component.html
,user-list.component.css
和user-list.component.spec.ts
) - 将
user-list
添加为最近模块的@NgModule
装饰器中的声明。