Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Firebase data using AngularJS

i have a data in firebase like this:

firebase_data {
    -JGc5X37NDuvmJylmx0s: Object {
        name: 'John Doe',
        age: 21
    }
    -JGnGJlTjyAxFT-Vn48Y: Object {
        name: 'Jane Doe',
        age: 22
    }
}

in my controller:

$scope.firebase = $firebase(new Firebase("https://firebase_data.firebaseio.com"));

my view:

<input type="text" ng-model="search" />
<ul ng-repeat="(key, value) in firebase | filter:search">  
    <li><a href="{{ key }}">{{ value.name }}</a></li>
</ul>

the filter is not working. how can i make the filter work?

like image 467
junerey Avatar asked Mar 02 '14 16:03

junerey


2 Answers

Use orderByPriority to convert your Firebase object to an array.

<input type="text" ng-model="search" />
<ul ng-repeat="(key, value) in firebase | orderByPriority | filter:search">  
    <li><a href="{{ key }}">{{ value.name }}</a></li>
</ul>
like image 87
Kato Avatar answered Nov 17 '22 05:11

Kato


I think firebase returns as object and angular's filter will filter only arrays and does not filter object

You can create custom filter and filter. I have created example for that using firebase object

http://plnkr.co/edit/tiSsswXQWgAPPv6ozqOm?p=preview

Please let me know if anything

like image 31
madhured Avatar answered Nov 17 '22 03:11

madhured