I learn best by having a "project" to work on. I'm learning angular 1.x by making a golf course listing app.
I have a json file I'm using with all the data. This app has a general text search, and 8 switches one can set to filter the region of the state and the type of golf course. I've got text search working great. I hacked up some of that code to make a single filter for "course type" and it actually works. But as soon as I try to make a second filter it breaks. I'll post my code below, but it is probably hacky.
What's the best way to put together EIGHT true/false switches into a filter or filters, and also combine that with a text search? I figure filter first, then text search the filtered results.
The html ng-repeat (if I take out the 2nd "private" filter, the public one works:
<div ng-repeat="course in items | searchFor:data.searchString | orderBy: 'name' | publicFilter:data.publicCourse | privateFilter:data.privateCourse " >
The filters (first one works by itself):
.filter('publicFilter', function(){
return function(arr, publicCourse){
var result = [];
if(publicCourse == true ){
angular.forEach(arr, function(item){
if(item.coursetype.toLowerCase().indexOf('public') !== -1){result.push(item);}
});
return result;
};
}
})
.filter('privateFilter', function(){
return function(arr, privateCourse){
var result = [];
if(privateCourse == true ){
angular.forEach(arr, function(item){
if(item.coursetype.toLowerCase().indexOf('private') !== -1){result.push(item);}
});
return result;
};
}
})