I am using a custom directive to show/hide a div
import {
Directive,
TemplateRef,
ViewContainerRef,
Input,
OnInit
} from '@angular/core';
import { LocalStorageConstants } from 'src/app/core/constants/local-storage.constants';
@Directive({
selector: '[isAdminRole]'
})
export class AuthDirective implements OnInit {
condition: boolean;
@Input() set isAdminRole(condition: boolean) {
this.condition = condition;
}
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef
) {}
ngOnInit() {
const privilegeRole = localStorage.getItem(
LocalStorageConstants.PRIVILEGE_ROLE
);
setTimeout(() => {
if (privilegeRole === 'ADMIN' && this.condition) {
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
})
}
}
<div *isAdminRole="true">Hi</div>
<div *isAdminRole="true">Bye</div>
but i am passing true or false from here, which is working the way i expect it too but i want to pass string like ADMIN
so that i can have a single check rather than multiple
any idea on how to do it