I want to create the searching filter from checkbox. So if I have checked steak and pizza filter then all the food with tags steak or pizza are shown in the list.
The problem is in the function that push tags to searchFilter array, when i check the tags 'pizza' the size array is zero then after push it is 1, but when I check other tags 'steak' the size array is still 0 then after push it is 1.
This is my code:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ion-list>
<ion-item ng-controller="FoodsCtrl" class="list card" ng-repeat="tag in tags">
<div class="item item-head">
<ion-checkbox ng-model="filter.checked" class="checkbox-energized" ng-change="addTag(tag)">{{tag.name}}</ion-checkbox>
</div>
</ion-item>
<ion-list>
</body>
</html>
Controller:
$scope.searchFilters = [];
$scope.addTag = function(tag) {
var check = $scope.filter.checked;
if(check)
{
alert('-' + $scope.searchFilters.length);
$scope.searchFilters.push({
name: tag.name
});
alert($scope.searchFilters.length);
}
else
{
var index = $scope.searchFilters.indexOf(tag.name);
alert(index);
if (index > -1) {
$scope.searchFilters.splice(index, 1);
}
alert($scope.searchFilters.length);
}
};
Thanks.