Skip to content

Instantly share code, notes, and snippets.

@fdonzello
Last active May 12, 2021 08:53
Show Gist options
  • Save fdonzello/46419db3dfde22a516295189da93254d to your computer and use it in GitHub Desktop.
Save fdonzello/46419db3dfde22a516295189da93254d to your computer and use it in GitHub Desktop.
Usage of the if-granted component
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {UserTypes} from '../../../models/models';
@Component({
selector: 'app-my-home',
template: `
This is visible to Admin, User and Guest.
<app-if-granted [allowedRoles]="[userTypes.Admin, userTypes.User]">
<!-- This is visible only to Admin and User -->
<button>Yes, I can!</button>
</app-if-granted>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyHomeComponent implements OnInit {
userTypes = UserTypes;
constructor() {
}
ngOnInit(): void {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment