生成命令用法

你可以使用 ng generateng 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.tsuser-list.component.htmluser-list.component.cssuser-list.component.spec.ts
  • user-list 新增為最近模組的 @NgModule 裝飾器中的宣告。