import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; @Directive({ selector: '[cVisible]', standalone: true }) export class VisibleDirective { constructor( private templateRef: TemplateRef, private viewContainer: ViewContainerRef ) { } private hasView!: boolean; @Input() 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; } } }