Reputation: 31
I want filter with angularjs. How to find amen in amenities. amen = 1; amenities = "1, 3, 7, 9, 12";
This is my code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<input type="checkbox" name="more_filter[]" value="1" class="pull-left amenities" id="amen-1" ng-checked="false">
amenities = "1, 3, 7, 9, 12";
//amen 1
$( "#amen-1" ).on( "click", function() {
var amen = document.getElementById("amen-1").val();
$scope.amen = amen;
$scope.$apply();
$scope.ot_Filter = function (location) {
return location.amenities == $scope.amen;
};
});
I want search amen in amenities. How do I make a change on this line :
location.amenities == $scope.amen
thank you..
EDIT: Problem solved with @Gonzalo's help:
<input type="checkbox" name="more_filter[]" value="1" class="pull-left amenities" ng-click="am_1();" id="map-search-amenities-1">
$scope.am_1 = function()
{
var kontrol = document.getElementById("map-search-amenities-1").checked;
if (kontrol==true) {
$scope.ot_Filter = function (location) {
return location.amenities.indexOf(1)==0;
};
} else {
$scope.ot_Filter = function (location) {
return location.amenities;
};
}
}
Upvotes: 0
Views: 43
Reputation: 12682
Use indexOf()
javascript built in function to search in the string.
location.amenities.indexOf(<yoursearch>);
another hint:
you should use ng-click
rather than on('click')
. You would remove scope.$apply()
with that
Upvotes: 0