, DOM , :
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
@Directive({ selector: '[customNgIf]' })
export class CustomNgIfDirective {
@Input("customNgIf") condition: boolean;
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef) {
}
ngOnInit() {
if (condition) {
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
}
}
:
<div *customNgIf="expression">
Test
</div>