UNPKG

@pepperi/core

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.0.5.

29 lines (22 loc) 794 B
import {Injectable, TemplateRef, ViewContainerRef} from '@angular/core'; @Injectable({ providedIn: 'root', }) export class PortalService { private targets: Map<string, ViewContainerRef>; constructor() { this.targets = new Map<string, ViewContainerRef>(); } addTarget(targetName: string, viewContainer: ViewContainerRef) { this.targets.set(targetName, viewContainer); } attach(targetName: string, template: TemplateRef<any>) { this.getTarget(targetName)?.createEmbeddedView(template); } clear(targetName: string) { this.getTarget(targetName)?.clear(); } private getTarget(targetName: string) { return this.targets.has(targetName) ? this.targets.get(targetName) : null; } }