TypeScript - 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.ts בתוך app.module.ts ואת my-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 כמו שהוצהר בוויקי
Angular 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
תשובה #1
כשאתה מייצר את המודול, אתה יכול להשתמש בדגל -m ולציין את השם של המודול שבו אתה רוצה לרשום אותו. כלי שורת הפקודה ירשום את המודול עבורך.
תשובה #2
אני לא בטוח למה -m לא עובד אבל אתה יכול לייבא אותם ידנית, זה לוקח שתי שניות שלמות.
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.
]
})
בנימה צדדית, אין סיבה לכלול את המודול פעמיים באף אחד מהשמות. במקום זאת פשוט השתמש ב-my-test.module.ts ו-my-test-two.module.ts
