I have a simple JSON object in my javascript, and I want to filter it when a button is clicked.
I looked around and found this. So far I have this:
$scope.myFunc = function(a) {
for(meal in $scope.mealTypes){
var t = $scope.mealTypes[meal];
if(t.on && a.type.indexOf(t.name) > -1){
return true;
}
}
};
$scope.mealTypes = {Breakfast: false, mainMeal:false};
This is my HTML:
<input id="checkBox" type="checkbox" name="Breakfast" value="Breakfast" data-ng-model="mealTypes.breakfast">
<input id="checkBox" type="checkbox" name="mainmeal" value="Main Meal" data-ng-model="mealTypes.mainMeal">
Then I aim to iterate the array and display the checked button pressed (I wish to display the names):
<span ng-repeat="reciepe in reciepes | filter:search" id="filtertag" name="hello">{{ reciepe.type }}
<span id="filtertagRemove">
<a href="google.com">remove</a>
</span>
</span>
Json:
$scope.reciepes =
[
{
"type": "Breakfast",
"title": "Chili con carne",
"description": "A spicy and fragrant chili with ground beef, kidney beans, tomatoes, onions and garlic. Best served over rice with a dollop of sour cream and some cheese on top.",
"ratings": 4,
"ingredients":
[
{
"vegetable": "40ml"
}
],
"method":
[
{
"1": "In a medium sized stock pot, heat the oil over medium heat. Saute onions, chile peppers andgarlic until soft."
}
]
},
{
"type": "Main Meal",
"title": "Main Meal",
"description": "A spicy and fragrant chili with ground beef, kidney beans, tomatoes, onions and garlic. Best served over rice with a dollop of sour cream and some cheese on top.",
"ratings": 4,
"ingredients":
[
{
"vegetable": "40ml"
}
],
"method":
[
{
"1": "In a medium sized stock pot, heat the oil over medium heat. Saute onions, chile peppers andgarlic until soft."
}
]
}]
Basically I aim to display the checkbox value on a div when it's pressed and filter the array. How should I do this?