@c-standard/angular-devui-extension
Version:
an extensional components lib for devui
70 lines (65 loc) • 3.57 kB
JavaScript
import * as i0 from '@angular/core';
import { EventEmitter, Directive, Input, Output, NgModule } from '@angular/core';
class ComponentLoaderDirective {
constructor(vcr) {
this.vcr = vcr;
this.keyExpr = 'id';
this.callback = new EventEmitter();
}
ngOnChanges(simple) {
if (simple) {
this.createComponent();
}
}
createComponent() {
this.vcr.clear();
const comp = this.dataSource?.find((t) => (t[this.keyExpr] == this.componentId))?.component;
if (comp) {
const compRef = this.vcr.createComponent(comp);
for (const key in this.componentInput) {
compRef.instance[key] = this.componentInput[key];
}
for (const func in this.componentOutput) {
// 事件的处理,组件的所有事件都会触发callback事件,在emit结果中标记是组件的哪个事件所触发
compRef.instance.func.subscribe((result) => this.callback.emit(result));
}
}
}
}
ComponentLoaderDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderDirective, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
ComponentLoaderDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.7", type: ComponentLoaderDirective, selector: "[dComponent]", inputs: { keyExpr: "keyExpr", dataSource: "dataSource", componentId: "componentId", componentInput: "componentInput", componentOutput: "componentOutput" }, outputs: { callback: "callback" }, usesOnChanges: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderDirective, decorators: [{
type: Directive,
args: [{
selector: '[dComponent]',
}]
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }]; }, propDecorators: { keyExpr: [{
type: Input
}], dataSource: [{
type: Input
}], componentId: [{
type: Input
}], componentInput: [{
type: Input
}], componentOutput: [{
type: Input
}], callback: [{
type: Output
}] } });
class ComponentLoaderModule {
}
ComponentLoaderModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
ComponentLoaderModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderModule, declarations: [ComponentLoaderDirective], exports: [ComponentLoaderDirective] });
ComponentLoaderModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ComponentLoaderModule, decorators: [{
type: NgModule,
args: [{
declarations: [ComponentLoaderDirective],
exports: [ComponentLoaderDirective],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { ComponentLoaderDirective, ComponentLoaderModule };
//# sourceMappingURL=c-standard-angular-devui-extension-component-loader.mjs.map