ng-devui
Version:
DevUI components based on Angular
83 lines (78 loc) • 3.74 kB
JavaScript
import { DOCUMENT, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Component, Inject, ViewChild, NgModule } from '@angular/core';
import { forEach } from 'lodash-es';
class PortalComponent {
constructor(appRef, doc) {
this.appRef = appRef;
this.doc = doc;
this.document = this.doc;
}
addContent() {
this.portalContainer = this.document.createElement('div');
this.viewRef = this.templateRef.createEmbeddedView(this);
forEach(this.viewRef.rootNodes, (node) => {
this.portalContainer.appendChild(node);
});
this.appRef.attachView(this.viewRef);
this.document.body.appendChild(this.portalContainer);
}
open() {
this.close();
this.addContent();
}
close() {
if (this.viewRef && this.portalContainer) {
this.document.body.removeChild(this.portalContainer);
this.viewRef.destroy();
this.viewRef = null;
this.portalContainer = null;
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PortalComponent, deps: [{ token: i0.ApplicationRef }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: PortalComponent, selector: "d-portal", viewQueries: [{ propertyName: "templateRef", first: true, predicate: ["templateRef"], descendants: true, static: true }], ngImport: i0, template: `
<ng-template #templateRef>
<ng-content></ng-content>
</ng-template>`, isInline: true }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PortalComponent, decorators: [{
type: Component,
args: [{
selector: 'd-portal',
template: `
<ng-template #templateRef>
<ng-content></ng-content>
</ng-template>`,
preserveWhitespaces: false,
}]
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }], propDecorators: { templateRef: [{
type: ViewChild,
args: ['templateRef', { static: true }]
}] } });
class PortalModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PortalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: PortalModule, declarations: [PortalComponent], imports: [CommonModule], exports: [PortalComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PortalModule, imports: [CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PortalModule, decorators: [{
type: NgModule,
args: [{
imports: [
CommonModule,
],
declarations: [
PortalComponent,
],
exports: [
PortalComponent,
],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { PortalComponent, PortalModule };
//# sourceMappingURL=ng-devui-portal.mjs.map