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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHluYW1pYy5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZy1keW5hbWljLWNvbXBvbmVudC9zcmMvbGliL2R5bmFtaWMuY29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFB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