-2

Controller

    app.controller('viewUsersController', function($scope, $http, $cookieStore, $modal) {
        $scope.cardsDisplayModeEnabled = true;
        $http.get('http://localhost:8080/myapp/user/all?access_token=' + $cookieStore.get("access_token")).
        then(function(response) {
            $scope.users = response.data;
        });

    $scope.filterStarWith = function(level) {
        var re = new RegExp('^' + "Supervisor", "i");
        return level.tfAccessLevel.match(re);
    };
})

HTML

 <select ng-controller="viewUsersController" ng-model="user.tfSupervisor.id" name="createSupervisor" id="createSupervisor" class="form-control">
    <option ng-repeat="level in users | filter:filterStarWith()">{{level.userFirstName}}</option>
</select>


Table : user
Id         username          accesslevel          
1            John               Admin
2            Mark               Supervisor
3            Chady              Admin

I have to list in option whose access level is "Supervisor"

Thanks,

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
Rajkumar
  • 25
  • 5
  • There is no specific question detail here or a concise problem statement. After you read [ask] update the question content with all relevant specifics. – charlietfl Nov 16 '16 at 02:44

3 Answers3

0

You can filter by access level directly within your ng-repeat.

ng-repeat="level in users | filter:{tfAccessLevel:'Supervisor'}"

Take a look at this answer: How to filter by object property in angularJS

Community
  • 1
  • 1
Isabelle Plante
  • 518
  • 3
  • 7
  • 20
0

You can simply do this, using existing filter option

 <select ng-model="user.id" name="createSupervisor" id="createSupervisor" class="form-control">
    <option ng-repeat="level in users  | filter: { accesslevel: 'Admin' }">{{level.userFirstName}}</option>
  </select>

DEMO

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

Since you are storing the entire data in your user object scope, you'll have access to both username and access level properties.

In this scenario, I don't see a reason to create a custom filter, as this can be handled by Angular's intelligent filter expression.

If you read the angular api, the filter can be using in HTML Template binding.

A filter in HTML template binding should be expression, propertyKey or comparator. In your case, you need to just inject your filter as

 <option ng-repeat="level in users | filter:filterStarWith "{{level.userFirstName}}</option>

or else

you can use something like this which is pretty straightforward.

<option ng-repeat="level in users | filter: {accesslevel: 'Supervisor' }"> {{level.userFirstName}}</option>
Sidd Thota
  • 2,040
  • 1
  • 20
  • 24