coreui-angular-ex
Version:
CoreUI Components Library for Angular
27 lines (21 loc) • 637 B
text/typescript
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
export class VisibleDirective {
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef
) { }
private hasView!: boolean;
set cVisible(condition: boolean) {
if (condition && !this.hasView) {
this.viewContainer.createEmbeddedView(this.templateRef);
this.hasView = true;
} else if (!condition && this.hasView) {
this.viewContainer.clear();
this.hasView = false;
}
}
}