Improve this doc View source

ifUserInGroup
directive in module stormpath

Description

Use this directive to conditionally show an element if the user is logged in and is a member of the group that is specified by the expression.

The attribute value MUST be one of:

  • A string expression, surrounded by quotes
  • A reference to a property on the $scope. That property can be a string or regular expression.

Note: This feature depends on the data that is returned by the CURRENT_USER_URI. Your server should expand the account's groups before returning the user. If you are using express-stormpath, simply use Automatic Expansion

Using Regular Expressions

If using a string expression as the attribute value, you can pass a regular expression by wrapping it in the literal syntax, e.g.

  • '/admins/' would match any group which has admins in the name
  • '/admin$/' would match any group were the name ends with admin

If referencing a scope property, you should create the value as a RegExp type, e.g.:

   $scope.matchGroup = new RegExp(/admins/);
 

All regular expressions are evaluated via RegExp.prototype.test

Usage

as attribute
<ANY if-user-in-group>
   ...
</ANY>

Example

<script type="text/javascript">
  function SomeController($scope){
    $scope.matchGroup = /admins/;
  }
<script>
<div ng-controller="SomeController">
  <h3 if-user-in-group="'admins'">
    Hello, {{user.fullName}}, you are an administrator
  </h3>

  <div if-user-in-group="'/admins/'">
     <!-- would match any group which has *admins* in the name -->
  </div>
  <div if-user-in-group="matchGroup">
     <!-- equivalent to the last example -->
  </div>
  <div if-user-in-group="'/admin$/'">
     <!-- would match any group were the name **ends with** *admin* -->
  </div>
</div>