Filter Multiple Angularjs With Array On Ng-click
I have two object. //First for items { catId : [1, 2, 3], name : 'My name is George' }, { catId : 1, name : 'My name is Bob' }, { catId : 2, name : 'My name is Trump' } And
Solution 1:
Try like this
// Code goes herevar app = angular.module('app', []);
app.controller('myController', function($scope){
$scope.items = [
{
Name: "My name is George",
catId: [ 1, 3, 7 ]
},
{
Name: "My name is Bob",
catId: 1
},
{
Name: "My name is Trump",
catId: 2
}];
$scope.cats = [
{
Name: "Hello",
Id: 1
},
{
Name: "World",
Id: 3
}];
$scope.setCatFilter = function(id){
$scope.catFilter = id;
}
})
/* Styles go here */span {
width: 20px;
display: inline-block;
cursor: pointer;
padding: 5px;
text-align: center;
margin-right: 5px;
background: red;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="app"ng-controller="myController"><div>Filter items</div><spanng-repeat="cat in cats"ng-click="setCatFilter(cat.Id)">{{cat.Id}}</span><div>Category</div><inputtype="text"ng-model = "serachName"><divng-repeat="item in items | filter:{catId:catFilter,Name:serachName}">
{{item.Name}}
</div></div>
Post a Comment for "Filter Multiple Angularjs With Array On Ng-click"