Currently I have a JSON file look like this:
[
{
"name":"Bánh bao nướng phô mai thịt",
"image":"banhbaonuongphomaithit",
"howtocook":"<h1>abc<\/h1>",
"video":"sY6bswxfVGM",
"category": "bakery"
},
{
"name":"Cháo móng giò hạt sen",
"image":"chaomonggiohatsen",
"howtocook":"Sample",
"video":"24vqCAXlQ0w",
"category": "appetizer"
},
{
"name":"Bánh mì chà bông nhân trứng muối",
"image":"banhmichabongnhantrungmuoi",
"howtocook":"Sample",
"video":"HhMj6jDIQrY",
"category": "bakery"
},
{
"name":"Cà chua muối kiểu kim chi",
"image":"cachuamuoikieukimchi",
"howtocook":"Sample",
"video":"aOYlyEiV3HQ",
"category": "appetizer"
}
]
This is my JS
var pageControllers = angular.module('pageControllers', [])
.config(function($sceProvider) {
// Completely disable SCE. For demonstration purposes only!
// Do not use in new projects or libraries.
$sceProvider.enabled(false);
});
;
pageControllers.controller('HomeController', ['$scope', '$http', function($scope, $http) {
$http.get('js/foods.json').success(function(data) {
$scope.games = data;
});
}]);
And HTML
<div class="row"> <!--First row-->
<div class="col-xs-12 col-sm-4 col-lg-3" ng-repeat = "item in games | filter: query">
<a href="#/details/{{games.indexOf(item)}}" class="thumbnail" data-toggle="tooltip" data-placement="bottom" title="{{item.name}}"><img ng-src="img/foods/{{item.image}}.png" alt="{{item.name}}"></a>
<div class="caption">
<h5 class="text-center" ng-model="foodname">{{item.name}}</h5>
<form name="uploadItem" ng-submit="addFavorite()" novalidate ng-controller = "UploadController" ng-show = "currentUser" ng-controller = "RegistrationController">
<div class="form-group">
<input type="text" name="name" class="form-control" ng-model="foodname" ng-init="foodname='{{item.name}}'" value="{{item.name}}" >
</div>
<button type="submit" class="btn btn-block" style="background-color: #FF4500">Add to favorite</button><br>
</form>
</div>
</div><!--End of first row-->
</div>
And I want to display every records filter by category, for example when I filter appetizer or making it in a category page, all records that have appetizer category should displayed. I've though about reorganize the JSON file but still do not know how to filter it.
OrderBytong-repeat = "item in games | filter: query | orderBy : 'Category'"