Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  30] [ 2]  / answers: 1 / hits: 21227  / 11 Years ago, wed, january 22, 2014, 12:00:00

i have json data, and i want it show by filter such as genre.
Last question from How to filter JSON-Data with AngularJs? dont work to me.



myapp.js



var myApp = angular.module('myApp', []);

myApp.controller('myApp', function($scope) {

$scope.isoffice = function(apps) {
return apps[0].genre === office;
};

$scope.apps = [
{
id: stardict,
genre: aksesoris,
name: Stardict
},
{
id: libreoffice,
genre: office,
name: LibreOffice
}];
}


my index.html



<div ng-repeat=app in apps | filter:isoffice>
{{apps[0].name}}
</div>


do i missing somethink?
thank you..


More From » json

 Answers
54

You don't need a comparator function to do that filtering. You can use this:



<div ng-repeat=app in apps | filter:{genre:'office'}>
{{app.name}}
</div>


Note that I use app.name to display the current app generated by ngRepeat. apps[0].name will repeatedly display the first entry (if multiple entries match your filter).



demo fiddle



If you want to use a comparator function, this will work (one object is sent in each time so you don't want to reference it as an array):



$scope.isoffice = function(apps) {
return apps.genre === office;
};


comparator demo


[#73025] Monday, January 20, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;