2

环境: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)

这是我的模块

@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 认为我已经声明了它们。我怎样才能解决这个问题?

4

1 回答 1

2

您需要移动ModalBackdropComponent到它自己的模块(或共享组件和指令的另一个模块,并导入要使用共享组件的共享模块,而不是将组件直接导入多个模块。

于 2016-08-22T06:51:25.557 回答