1

我已經生成的模塊:Angular-CLI。如何在當前版本中註冊新模塊?

$ ng generate module myTestModule 
installing module 
    create src/app/my-test-module/my-test-module.module.ts 

$ ng generate module myTestModule2 
installing module 
    create src/app/my-test-module2/my-test-module2.module.ts 

我平常文件描述了主模塊app.module.ts。我怎樣才能在my-test-module.module.tsapp.module.tsmy-test-module2.module.ts中註冊模塊my-test-module.module.ts


更多的細節,以幫助改善答案

$ ng generate --help 

module <name> <options...> 
    aliases: m 
    --spec (Boolean) Specifies if a spec file is generated. 
    --flat (Boolean) Flag to indicate if a dir is created. 
    --routing (Boolean) (Default: false) Specifies if a routing module file should be generated. 
    --app (String) Specifies app name to use. 
    aliases: -a <value> 

沒有-m--module這裏就像wiki

我的角度CLI聲明:

$ ng -v 

@angular/cli: 1.0.1 
node: 7.4.0 
@angular/common: 4.1.3 
@angular/compiler: 4.1.3 
@angular/core: 4.1.3 
@angular/forms: 4.1.3 
@angular/http: 4.1.3 
@angular/platform-browser: 4.1.3 
@angular/platform-browser-dynamic: 4.1.3 
@angular/router: 4.1.3 
@angular/cli: 1.0.1 
@angular/compiler-cli: 4.1.3 

一些更多的細節來幫助改善答案v2 我已經更新angular-cli到v1.2.1。我可以使用別名-m

module <name> <options...> 
    aliases: m 
    --spec (Boolean) Specifies if a spec file is generated. 
    --flat (Boolean) Flag to indicate if a dir is created. 
    --routing (Boolean) (Default: false) Specifies if a routing module file should be generated. 
    --app (String) Specifies app name to use. 
    aliases: -a <value> 
    --module (String) Specifies where the module should be imported. 
    aliases: -m <value> 

所以我嘗試

$ ng g m MyTestModuleModule34 -m AppModule 

installing module 
Specified module does not exist 

但指定模塊中src/app/app-module.ts

+2

通過做你要做的*任何*模塊;將其添加到相關的'進口'。 – jonrsharpe

+1

將test_ module.module.ts;中的'import {TestModuleModule}添加到a​​pp.ts的頂部,將'imports:[TestModuleModule,...]'添加到'@ NgModule'。另外,您可能需要考慮執行'ng generate module my-test',因爲它已經附加了模塊部分。 –

+0

@ Z.Bagley爲什麼要將'TestModuleModule'添加到'@ NgModule'''''塊?我預計它應該在'聲明'塊中。 – Sergii

回答

1

當您生成模塊,你可以使用-m標誌和指定名稱存在您要註冊的模塊。然後cli將爲您註冊模塊。

+0

你能否提高你的幫助?對不起,這對我來說還不夠清楚。我試過'生成模塊MyTestModuleModule3 -m AppModule',結果是'選項'-m'沒有用generate命令註冊。運行'ng generate --help'獲取支持的選項列表。' – Sergii

+0

我檢查了一些[示例](https://github.com/angular/angular-cli/wiki/generate-module)它似乎我應該正好使用'-m'或'--module'。可能是我應該修理別的地方?我檢查了'ng -v'的結果是'@ angular/cli:1.0.1'和​​其他角度依賴關係是'4.1.3' – Sergii

+0

對不起......我的飛機正在着陸,我耗盡了時間...將發佈一個例如,當我可以。 – DeborahK

1

我不知道爲什麼-m不工作,但你可以手動導入它們,它需要整整2秒。

app.module.ts

@NgModule({ 
    imports: [ 
    MyTestModule 
    ] 
}) 

我試驗module.module.ts

@NgModule({ 
    imports: [ 
    MyTestModule2 // This should be named MyTest2Module for naming consistancy throughout your app. i.e. all module names should end with the word module. See the Angular Style Guide for more info. 
    ] 
}) 

在一個側面說明,沒有任何理由,包括模塊兩倍任何名字。取而代之的只是使用my-test.module.tsmy-test-two.module.ts