6

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?

1

2 Answers 2

10

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Today, orderByPriority is deprecated, right? I've been trying to use this but it's doesn't work.
In the latest versions just use $asArray which already provides sorted values.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.