I am using Angular CLI 6.1.4 and i am currently struggeling with the following issue:
I created a structural directive which should work similar to *ngIf
but taking html-element name or id attribute values to decide whether its shown or not.
The problem is that i just cant get my <button>
's name attribute passed to my structural directive.
My Button:
<button name="bla" *ngIfVisible="this.name">TEST</button> //this is not working!
My structural directive
import { Directive, TemplateRef, ViewContainerRef, Input } from '@angular/core';
import { UserPermissionService } from '../services/user-permission.service';
@Directive({
selector: '[ngIfVisible]'
})
export class NgIfVisible {
constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, private userPermissionService: UserPermissionService) { }
@Input()
set ngIfVisible(name: any) {
if (this.userPermissionService.isElementVisible(name)) {
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
}
}
I simply want that the name bla
is passed to the directive...
I already tried:
<button #name="bla" *ngIfVisible="name">TEST</button>
and
<button name="bla" *ngIfVisible="$(this).attr('name')">TEST</button>
But none of them works... Please Help!