80 lines
9.4 KiB
JavaScript
80 lines
9.4 KiB
JavaScript
|
import { Component, EventEmitter, Injector, Input, Output, } from '@angular/core';
|
||
|
import { DynamicComponentInjectorToken, } from './component-injector';
|
||
|
import * as i0 from "@angular/core";
|
||
|
/**
|
||
|
* @public
|
||
|
*/
|
||
|
export class DynamicComponent {
|
||
|
constructor(vcr) {
|
||
|
this.vcr = vcr;
|
||
|
this.ndcDynamicCreated = new EventEmitter();
|
||
|
this.componentRef = null;
|
||
|
}
|
||
|
ngOnChanges(changes) {
|
||
|
if (DynamicComponent.UpdateOnInputs.some((input) => changes.hasOwnProperty(input))) {
|
||
|
this.createDynamicComponent();
|
||
|
}
|
||
|
}
|
||
|
createDynamicComponent() {
|
||
|
this.vcr.clear();
|
||
|
this.componentRef = null;
|
||
|
if (this.ndcDynamicComponent) {
|
||
|
this.componentRef = this.vcr.createComponent(this.ndcDynamicComponent, {
|
||
|
index: 0,
|
||
|
injector: this._resolveInjector(),
|
||
|
projectableNodes: this.ndcDynamicContent,
|
||
|
ngModuleRef: this.ndcDynamicNgModuleRef,
|
||
|
environmentInjector: this.ndcDynamicEnvironmentInjector,
|
||
|
});
|
||
|
this.ndcDynamicCreated.emit(this.componentRef);
|
||
|
}
|
||
|
}
|
||
|
_resolveInjector() {
|
||
|
let injector = this.ndcDynamicInjector || this.vcr.injector;
|
||
|
if (this.ndcDynamicProviders) {
|
||
|
injector = Injector.create({
|
||
|
providers: this.ndcDynamicProviders,
|
||
|
parent: injector,
|
||
|
});
|
||
|
}
|
||
|
return injector;
|
||
|
}
|
||
|
}
|
||
|
DynamicComponent.UpdateOnInputs = [
|
||
|
'ndcDynamicComponent',
|
||
|
'ndcDynamicInjector',
|
||
|
'ndcDynamicProviders',
|
||
|
'ndcDynamicContent',
|
||
|
'ndcDynamicNgModuleRef',
|
||
|
'ndcDynamicEnvironmentInjector',
|
||
|
];
|
||
|
/** @nocollapse */ DynamicComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DynamicComponent, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Component });
|
||
|
/** @nocollapse */ DynamicComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.3", type: DynamicComponent, isStandalone: true, selector: "ndc-dynamic", inputs: { ndcDynamicComponent: "ndcDynamicComponent", ndcDynamicInjector: "ndcDynamicInjector", ndcDynamicProviders: "ndcDynamicProviders", ndcDynamicContent: "ndcDynamicContent", ndcDynamicNgModuleRef: "ndcDynamicNgModuleRef", ndcDynamicEnvironmentInjector: "ndcDynamicEnvironmentInjector" }, outputs: { ndcDynamicCreated: "ndcDynamicCreated" }, providers: [
|
||
|
{ provide: DynamicComponentInjectorToken, useExisting: DynamicComponent },
|
||
|
], usesOnChanges: true, ngImport: i0, template: '', isInline: true });
|
||
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DynamicComponent, decorators: [{
|
||
|
type: Component,
|
||
|
args: [{
|
||
|
selector: 'ndc-dynamic',
|
||
|
standalone: true,
|
||
|
template: '',
|
||
|
providers: [
|
||
|
{ provide: DynamicComponentInjectorToken, useExisting: DynamicComponent },
|
||
|
],
|
||
|
}]
|
||
|
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }]; }, propDecorators: { ndcDynamicComponent: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicInjector: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicProviders: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicContent: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicNgModuleRef: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicEnvironmentInjector: [{
|
||
|
type: Input
|
||
|
}], ndcDynamicCreated: [{
|
||
|
type: Output
|
||
|
}] } });
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHluYW1pYy5jb21wb25lbnQuanMi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