I am working on creating a custom Directive that can dynamically add or remove itself from the DOM similar to *ngIf functionality. Here is what I have so far:
@Directive({
selector: '[myDirective]',
host: {
'[hidden]': 'hidden',
}
})
export class MyDirective {
constructor(private myService : MyService) {
}
hidden() {
return !this.myService.valid;
}
However, what I am aiming for is something like this:
@Directive({
selector: '[myDirective]',
host: {
'*ngIf': 'hidden',
}
})
...
Unfortunately, using '*ngIf': 'hidden'
in the host
of the Directive is throwing an error:
Can't bind to 'ngIf' since it isn't a known property of 'button'.
Similarly, trying '[ngIf]': 'hidden'
is not achieving the desired result.
So, I am seeking advice on how to implement ngIf functionality within a Directive.