I am creating a custom directive to hide elements on certain conditions but its not working as per the instruction i found googling.
All other things working but element is not effecting display property
Use of directive:
<div manAuthorized [permission]="'permission-string'" class="col-2 data-object-link">
Actual directive:
@Directive({
selector: '[manAuthorized]'
})
export class AuthorizedDirective implements OnInit {
@Input() permission: string;
private userObservable: Observable<UserAuthorizations>;
private currentUser: any;
constructor(private elementRef: ElementRef, private configService: ConfigService, private currentUserService: CurrentUserService) {
this.userObservable = this.currentUserService.getCurrentUser();
}
ngOnInit(): void {
this.userObservable.subscribe((user) => {
this.currentUser = user;
if (!this.authorized()) {
this.elementRef.nativeElement.display = 'none';
}
});
}
private authorized() {
return true;
}
}