7 ComponentFactoryResolver,
9 OnChanges, OnDestroy, AfterViewInit
10 } from '@angular/core';
11 import {Component as TopologyTemplate} from 'app/models';
13 // Helper component to add dynamic tabs
15 selector: 'panel-tab',
16 template: `<div #content></div>`
18 export class PanelTabComponent implements OnChanges, OnDestroy, AfterViewInit {
19 @ViewChild('content', { read: ViewContainerRef }) content;
20 @Input() isActive:boolean;
21 @Input() panelTabType;
23 @Input() isViewOnly:boolean;
24 @Input() component:TopologyTemplate;
25 @Input() componentType;
26 cmpRef: ComponentRef<any>;
27 private isViewInitialized: boolean = false;
29 constructor(private componentFactoryResolver: ComponentFactoryResolver,
30 private cdRef: ChangeDetectorRef) { }
33 if (!this.isViewInitialized || !this.isActive) {
37 this.cmpRef.destroy();
40 let factory = this.componentFactoryResolver.resolveComponentFactory(this.panelTabType);
41 this.cmpRef = this.content.createComponent(factory);
42 this.cmpRef.instance.input = this.input;
43 this.cmpRef.instance.isViewOnly = this.isViewOnly;
44 this.cmpRef.instance.component = this.component;
45 this.cmpRef.instance.componentType = this.componentType;
46 this.cdRef.detectChanges();
50 this.updateComponent();
54 this.isViewInitialized = true;
55 this.updateComponent();
60 this.cmpRef.destroy();