How to filter JSON-Data with AngularJs? How to filter JSON-Data with AngularJs? angularjs angularjs

How to filter JSON-Data with AngularJs?


Since your object model is kind of complex I would recommend using custom filtering function:

$scope.isActive = function(user) {    return user.User.Stats[0].active === "1";};

and then in your HTML:

<div ng-repeat="user in _users | filter:isActive">    {{user.User.userid}}</div>

Here is the working jsFiddle: http://jsfiddle.net/pkozlowski_opensource/4kzzy/3/

Be sure to check angular's documentation on filters if you need more info: http://docs.angularjs.org/api/ng.filter:filter


Taking @pkozlowski.opensource a bit further and allowing live filtering of items/users:

http://jsfiddle.net/hbyNN/

<div ng-controller="MyCtrl">  <label>userid substring filter:</label>  <input ng-model="zzzzz">  <div ng-repeat="user in _users | filter:isInteresting">       <pre>{{user | json}}</pre>  </div></div>

And:

   $scope.isInteresting = function (user) {    if ($scope.zzzzz == undefined) {        return true;    }    return user.userid.indexOf($scope.zzzzz) !== -1;};