import { Directive, ElementRef, Input, OnInit } from '@angular/core'; import { ProfileService } from '../../services/profile.service'; @Directive({ selector: '[appPrivilege]' }) export class PrivilegeDirective implements OnInit { @Input() checkPrevilege: string; constructor( private elem: ElementRef, private profileService: ProfileService ) { } ngOnInit() { if ( this.profileService.privileges.findIndex(x => x === this.checkPrevilege) <= -1 ) { this.elem.nativeElement.style.display = 'none'; } } }