NgbModal 不从另一个组件中包含的组件打开模态

NgbModal not opening modal from component included in another component

我正在使用 Anuglar 6

我有两个组件 accountprofileaccount 组件添加到 app-component

我想通过单击 account-component 中的按钮打开 profile-component

但这给我一个错误

Error: No component factory found for NgbModalBackdrop. Did you add it to @NgModule.entryComponents?

应用程序模块看起来像

@NgModule({
  imports:      [ BrowserModule, FormsModule ],
  declarations: [ AppComponent, HelloComponent, AccountComponent, ProfileComponent ],
  entryComponents: [
    ProfileComponent
  ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

这是工作示例:https://stackblitz.com/edit/angular-uwobqm

这是一个很大的模糊猜测,但您可能需要像这样在 app.module.ts

中导入 NgbModule
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

@NgModule({
  imports: [
    NgbModule.forRoot()
  ]
})

这应该会修复您 运行 遇到的错误。

它通过在我的模块文件中添加 NgbModule 为我工作。

import {  NgbModule } from '@ng-bootstrap/ng-bootstrap';


@NgModule({
     imports: [...
     NgbModule,
      ....],
     declarations: [],
     entryComponents: [...]
     })