Open Robbe64 opened 6 years ago
I am also looking forward to get a feature like this. The easiest way would be to remove the element but not to render the element at all would be really nice.
Easy way but not nice way:
import { autoinject, customAttribute, bindable } from 'aurelia-framework';
import AuthorizationService from './authorization-service';
// Sample usage:
// global-permission-show="can: AddUsers"
@autoinject()
@customAttribute('global-permission-if')
export class GlobalPermissionIf {
@bindable can = '';
@bindable check = true;
get canPermissions(): string[] {
return this.can ? this.can.replace(' ', '').split(',') : [];
}
private element: any;
constructor(element: Element, private authorizationService: AuthorizationService) {
this.element = element;
}
bind() {
if (this.check && !this.authorizationService.isAuthorizedByPermissionName(this.canPermissions)) {
this.hideElement();
}
}
private hideElement() {
this.element.parentElement.removeChild(this.element);
}
}
It would be nice to don't even render elements instead of hiding them. Is there a chance to get this feature?