How can I create a custom directive(e.g. appCheckPermission ) to check if user can view a link or button base on routerLink that applied to that element.
<button [routerLink]="['/users/edit', userId]" appCheckPermission ></button>
p.s: there is a property that save routerlink value
nativeElement.attributes["ng-reflect-router-link"].value
but can not be access via custom directive.
It should be accessible as an Input
property and inside the lifecycle hooks
@Directive({ selector: '[appCheckPermission]' })
export class AppCheckPermissionDirective implements OnInit {
@Input() routerLink: any;
ngOnInit(): void {
console.log(this.routerLink);
}
...
}