import { Component, ElementRef, ComponentFactoryResolver, ViewContainerRef } from '@angular/core'; import { RdComponent } from '../../base/rdComponent'; @Component({ selector: 'rd-popover-instance', template: "" }) export class PopoverInstance extends RdComponent { private onDismissCallback; private contentReferance; constructor(private view: ViewContainerRef, private loader: ComponentFactoryResolver) { super(); } open(data, contentComponent, target, onDismissCallback) { if (this.contentReferance) this.contentReferance.destroy(); this.onDismissCallback = onDismissCallback; (window).popoverInstanceClose = function (data) { this.contentReferance.instance.close(data); }.bind(this); let factory = this.loader.resolveComponentFactory(contentComponent); let ref = this.view.createComponent(factory); this.contentReferance = ref; ref.instance["element"] = ref.location; ref.instance["target"] = target; ref.instance["onOpen"](data); ref.changeDetectorRef.detectChanges(); } close(data) { this.contentReferance.destroy(); this.onDismissCallback(data); } }