blob: c148a4e57983e6a6d4c8e4eb88e7dbe6f56d3e75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import { NgModule, Component, Compiler, ViewContainerRef, ViewChild, Input, ComponentRef, ComponentFactoryResolver, ChangeDetectorRef } from '@angular/core';
import {Component as TopologyTemplate} from "app/models";
import { SdcUiServices } from "onap-ui-angular";
// Helper component to add dynamic tabs
@Component({
selector: 'panel-tab',
template: `<div #content></div>`
})
export class PanelTabComponent {
@ViewChild('content', { read: ViewContainerRef }) content;
@Input() isActive:boolean;
@Input() panelTabType;
@Input() input;
@Input() isViewOnly:boolean;
@Input() component:TopologyTemplate;
@Input() componentType;
cmpRef: ComponentRef<any>;
private isViewInitialized: boolean = false;
constructor(private componentFactoryResolver: ComponentFactoryResolver,
private cdRef: ChangeDetectorRef) { }
updateComponent() {
if (!this.isViewInitialized || !this.isActive) {
return;
}
if (this.cmpRef) {
this.cmpRef.destroy();
}
let factory = this.componentFactoryResolver.resolveComponentFactory(this.panelTabType);
this.cmpRef = this.content.createComponent(factory);
this.cmpRef.instance.input = this.input;
this.cmpRef.instance.isViewOnly = this.isViewOnly;
this.cmpRef.instance.component = this.component;
this.cmpRef.instance.componentType = this.componentType;
this.cdRef.detectChanges();
}
ngOnChanges() {
this.updateComponent();
}
ngAfterViewInit() {
this.isViewInitialized = true;
this.updateComponent();
}
ngOnDestroy() {
if (this.cmpRef) {
this.cmpRef.destroy();
}
}
}
|