Angular 4 - Structural directive Can't bind to X since it isn't a known property of Y -
i'm trying write structural directive remove , display components according user permissions.
this code , error recive
import { credantialsstorageservice } './_services/credantials-storage.service'; import { directive, input, templateref, viewcontainerref } '@angular/core'; import { } 'lodash'; @directive({ selector: '[accessroles]' }) export class accessrolesdirective { constructor( private templateref: templateref<any>, private viewcontainer: viewcontainerref, private readonly credantials: credantialsstorageservice) { } @input() set accessroles(roles: [string]) { let isvalidarraywithroles = roles != null && array.isarray(roles) && roles.length > 0; let isuserinoneoftheroles = isvalidarraywithroles && some(this.credantials.get().roles , role => roles.indexof(role) > -1); if (isuserinoneoftheroles) { this.viewcontainer.createembeddedview(this.templateref); } else { this.viewcontainer.clear(); } } }
<a class="nav-item nav-link text-uppercase" routerlink="/admin" routerlinkactive="active" *accessroles="[admin]"> <i class="fa fa-question-circle"></i> <span translate>admin</span> </a>
error: uncaught error: template parse errors: can't bind 'accessroles' since isn't known property of 'a'
any appreicated :-)
Comments
Post a Comment