I have created a simple Angular directive where I control whether an element will be shown or not. What I am unable to perform is the following:
- Modify an attribute of the element where this directive is used
- Add an html element to the same element
@Directive({
selector: '[needPermission]'
})
export class NeedPermissionDirective {
private visible = true;
constructor(private templateRef: TemplateRef < any > , private viewContainer: ViewContainerRef) {}
@Input() set needPermission(permissionId: string) {
if (this.visible === true) {
// TODO-1: Modify an attribute for an element within the templateRef
// TODO-2: Add an html element to the templateRef like a <div>
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
})
}
}