Skip to content
Jonathan Chase edited this page Aug 12, 2014 · 7 revisions

To render content dependent on whether a user has been authenticated and is a member of one or more required roles you need to do the following.

  1. Add a dependency to app.security in your module declaration.
  2. Inject the guardSvc into your controller and expose it on the controllers scope.
  3. Use the guardSvc.authorize function with the ngIf directive to control whether content is rendered. If no arguments are passed to the function authorize will return true for any authenticated user. To specify roles pass in an array of all role names ['user','administrator']. Note that if the user is in any of the supplied roles the user will be authorized.

For example:

<p class="bg-info" ng-if="guardSvc.authorized()">This paragraph will only show is you are currently signed in.</p>

<p class="bg-info" ng-if="guardSvc.authorized(['administrator'])">This paragraph will only show is you are currently signed in and the user is in the administrator role.</p>