typescript - Angular-CLI. Làm thế nào để đăng ký module mới trong module hiện tại?
Tôi đã tạo ra các mô-đun:
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
Tôi có tệp thông thường mô tả module chính app.module.ts. Làm thế nào tôi có thể đăng ký module my-test-module.module.ts trong app.module.ts và my-test-module2.module.ts trong my-test-module.module.ts?
Một số chi tiết thêm để giúp cải thiện câu trả lời
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>
không có -m hoặc --module ở đây như đã khai báo trên wiki
Angular CLI của tôi:
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
angular-cli lên v1.2.1. Tôi có thể sử dụng bí danh -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>
Vì vậy tôi cố gắng
ng g m MyTestModuleModule34 -m AppModule
installing module
Specified module does not exist
Nhưng module đã chỉ định có trong src/app/app-module.ts
Câu trả lời #1
Khi bạn tạo module, bạn có thể sử dụng cờ -m và chỉ định tên của module mà bạn muốn đăng ký. CLI sau đó sẽ đăng ký module cho bạn.
Câu trả lời #2
Tôi không chắc tại sao -m lại không hoạt động nhưng bạn có thể nhập chúng thủ công, chỉ mất đúng 2 giây.
app.module.ts
@NgModule({
imports: [
MyTestModule
]
})
my-test-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.
]
})
Ngoài ra, không có lý do gì để bao gồm Module hai lần trong bất kỳ tên nào. Thay vào đó chỉ cần sử dụng my-test.module.ts và my-test-two.module.ts
