小编jos*_*cos的帖子

如何使用特定的注入器在 ng-bootstrap 模式中打开组件?

我开始使用 ng-bootstrap modal 在弹出窗口中打开我的组件。我有很多组件,每个组件都需要您自己的注入器,因为每个组件都使用相同服务的不同实例。有没有办法像“ViewContainerRef”中那样传递组件和注入器:

let componentRef = viewContainerRef.createComponent(myComponentFactory, 0, myInjector, []);
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西:

NgbModal.open(MyComponet, myInjector);
Run Code Online (Sandbox Code Playgroud)

谢谢。


编辑以添加更多详细信息。

我需要注入的服务和对象是在运行时确定的,如下所示:

// Services
@Injectable()
export class MyService1 {
    constructor(
        @Inject('ServiceProvider') private _serviceProvider: any
    ) { }
}

@Injectable()
export class MyService2 {
    constructor(
        @Inject('ServiceProvider') private _serviceProvider: any
    ) { }
}

// Components
@Component({
   ...
})
export class CompA {
    constructor(
        @Inject('MyService') private _service: MyService1 | MyService2,
        @Inject('MyParentService') private _parentService: MyService1 | MyService2
    ) { }
}

@Component({
   ...
})
export class CompB { …
Run Code Online (Sandbox Code Playgroud)

bootstrap-modal ng-bootstrap angular

5
推荐指数
1
解决办法
3851
查看次数

标签 统计

angular ×1

bootstrap-modal ×1

ng-bootstrap ×1