Angularjs ng-repeat Filter Expression to Filter Values

Introduction:

This article explains how to use AngularJS to use ng-repeat filter expression to filter JSON object values to show or hide or update elements with example or AngularJS filter json object in controller with ng-repeat filter expression values example. By using filter option in ng-repeat we can filter JSON object values to enable/disable or show/hide required elements from JSON object.

To filter JSON object using ng-repeat filter expressions in AngularJS we need to write the code like as shown below  
-------------------------------------------------------------------------------------------------------------------------
 $scope.checkvalues = function (user) {
return user.id != "5";
}
-------------------------------------------------------------------------------------------------------------------------
If you want to check it in complete example you need to write the code like as shown below
-------------------------------------------------------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>angularjs filter json object to show/hide or update elements</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js">
</script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.sample = [{
id: '1',
name: 'A'
}, {
id: '2',
name: 'B'
}, {
id: '3',
name: 'C'
}, {
id: '4',
name: 'D'
}, {
id: '5',
name: 'E'
}, {
id: '6',
name: 'F'
}];

$scope.checkvalues = function (user) {
return user.id != "5";
}
});
</script>
</head>
<body data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<form id="form1">
<div ng-repeat="user in sample | filter:checkvalues">
{{user.name}} <br/>
</div>
</form>
</body>
</html>

-------------------------------------------------------------------------------------------------------------------------

Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment