在 .NET Core 專案中生成 Angular 2 元件時出現的預期錯誤(版本 0.8.3)

在 .NET Core 專案中生成新的 Angular 2 元件時,可能會遇到以下錯誤(從版本 0.8.3 開始):

Error locating module for declaration
        SilentError: No module files found

要麼

No app module found. Please add your new Class to your component. 
        Identical ClientApp/app/app.module.ts

[解]

  1. 將 app.module.client.ts 重新命名為 app.client.module.ts

  2. 開啟 app.client.module.ts:在宣告前加上 3 個點“…”並將宣告括在括號中。

    例如:[...sharedConfig.declarations, <MyComponent>]

  3. 開啟 boot-client.ts:更新匯入以使用新的 app.client.module 引用。

    例如:import { AppModule } from './app/app.client.module';

  4. 現在嘗試生成新元件:ng g component my-component

[說明]

Angular CLI 在專案中查詢名為 app.module.ts 的檔案,並嘗試查詢宣告屬性的引用以匯入元件。這應該是一個陣列(作為 sharedConfig.declarations 是),但是不會應用更改

[SOURCES]