ngx-admin-lte
Version:
AdminLTE theme for angular
81 lines • 7.44 kB
JavaScript
import * as tslib_1 from "tslib";
import { Component, Input, OnInit, OnDestroy, OnChanges, ComponentFactoryResolver, ViewContainerRef, ViewChild, ViewEncapsulation } from '@angular/core';
/**
* Component to dynamicly load other component
*/
let ComponentLoaderComponent = class ComponentLoaderComponent {
/**
* Component initialisation
*/
constructor(_factoryResolver) {
this._factoryResolver = _factoryResolver;
/**
* class of the component to load
*/
this.class_component = null;
/**
* data to pass to component
*/
this.data = null;
/**
* component reference
*/
this.componentRef = null;
}
/**
* Lifecycle hook OnInit
*/
ngOnInit() {
// Build the child component
const factory = this._factoryResolver.resolveComponentFactory(this.class_component);
this.componentRef = this.viewContainerRef.createComponent(factory);
// then give some data
this.setComponentData(this.data);
}
/**
* Lifecycle hook OnChanges, on modification of data send it to the child
*/
ngOnChanges(changes) {
this.setComponentData(changes);
}
/**
* Send data to the inner component
*/
setComponentData(changes) {
if (this.componentRef) {
// send data to component
Object.assign(this.componentRef.instance, changes);
// trigger component ngOnChange
this.componentRef.instance.ngOnChanges(changes);
}
}
/**
* Lifecycle hook OnDestroy
*/
ngOnDestroy() {
if (this.componentRef) {
this.componentRef.destroy();
}
}
};
ComponentLoaderComponent.ctorParameters = () => [
{ type: ComponentFactoryResolver }
];
tslib_1.__decorate([
Input()
], ComponentLoaderComponent.prototype, "class_component", void 0);
tslib_1.__decorate([
Input()
], ComponentLoaderComponent.prototype, "data", void 0);
tslib_1.__decorate([
ViewChild('destination', { read: ViewContainerRef, static: false })
], ComponentLoaderComponent.prototype, "viewContainerRef", void 0);
ComponentLoaderComponent = tslib_1.__decorate([
Component({
selector: 'app-component-loader',
encapsulation: ViewEncapsulation.None,
template: '<ng-container #destination ></ng-container>'
})
], ComponentLoaderComponent);
export { ComponentLoaderComponent };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9uZW50LWxvYWRlci5jb21wb25lbnQuanMiLCJzb3V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