环境:Angular 2 RC5,ng2-bootstrap ..从RC4升级到RC5
错误:
Uncaught EXCEPTION: Error in http://localhost:4200/app/forgot-username/forgot-username.component.html:39:60
ORIGINAL EXCEPTION: Type ModalBackdropComponent is part of the declarations of 2 modules: Myodule and AppModule!
ORIGINAL STACKTRACE:
Error: Type ModalBackdropComponent is part of the declarations of 2 modules: MyModule and AppModule!
at new BaseException (http://localhost:4200/vendor/@angular/compiler/src/facade/exceptions.js:27:23)
这是MyModule
@NgModule({
imports: [ DynamicFormModule, routes ],
declarations: [ MODAL_DIRECTIVES, ForgotUsernameComponent ],
exports: [ ],
providers: [BS_VIEW_PROVIDERS, ]
})
应用模块
@NgModule({
imports: [
BrowserModule,
// FormsModule,
routing,
HttpModule,
ForgotUsernameModule
],
declarations: [
// AppComponent
],
bootstrap: [ AppComponent]
})
export class AppModule {
}
我没有在AppModule中声明任何与ng2-bootstrap相关的工件(ModalBackdropComponent或任何其他工件),如您所见。所以我想弄清楚为什么Angular 2认为我已经宣布了它们。我该如何解决这个问题?
答案 0 :(得分:2)
您需要将ModalBackdropComponent
移动到它自己的模块(或者移动到另一个模块以获取共享组件和指令,并将共享模块导入您想要使用共享组件的位置,而不是将组件直接导入到多个组件和指令中模块。