mirror of
https://github.com/bitwarden/jslib
synced 2025-12-13 14:53:23 +00:00
Add support for setting up component factory resolvers in modal service (#471)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ApplicationRef,
|
||||
ComponentFactory,
|
||||
ComponentFactoryResolver,
|
||||
ComponentRef,
|
||||
EmbeddedViewRef,
|
||||
@@ -23,6 +24,10 @@ export class ModalConfig<D = any> {
|
||||
export class ModalService {
|
||||
protected modalCount = 0;
|
||||
|
||||
// Lazy loaded modules are not available in componentFactoryResolver,
|
||||
// therefore modules needs to manually initialize their resolvers.
|
||||
private factoryResolvers: Map<Type<any>, ComponentFactoryResolver> = new Map();
|
||||
|
||||
constructor(private componentFactoryResolver: ComponentFactoryResolver, private applicationRef: ApplicationRef,
|
||||
private injector: Injector) {}
|
||||
|
||||
@@ -51,6 +56,18 @@ export class ModalService {
|
||||
return modalRef;
|
||||
}
|
||||
|
||||
registerComponentFactoryResolver<T>(componentType: Type<T>, componentFactoryResolver: ComponentFactoryResolver): void {
|
||||
this.factoryResolvers.set(componentType, componentFactoryResolver);
|
||||
}
|
||||
|
||||
resolveComponentFactory<T>(componentType: Type<T>): ComponentFactory<T> {
|
||||
if (this.factoryResolvers.has(componentType)) {
|
||||
return this.factoryResolvers.get(componentType).resolveComponentFactory(componentType);
|
||||
}
|
||||
|
||||
return this.componentFactoryResolver.resolveComponentFactory(componentType);
|
||||
}
|
||||
|
||||
protected openInternal(componentType: Type<any>, config?: ModalConfig, attachToDom?: boolean):
|
||||
[ModalRef, ComponentRef<DynamicModalComponent>] {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user