Orderby object filter for pure Firebase JavaScript API

I found that angularFire always confuses me when it is used with the clean Firebase JavaScript API.

Let's say I have no idea how to call the datasapshot Firebase ss.name() , ss.hasChild(), ss.forEach() , etc. in angularFire.

So, I decided to use only the Firebase JavaScript API, because I realized that it already has two-way data binding (explicit) using AngularJS without using angularFire.

Demo without ngFire

But I had a problem with ng-repeat . The returned data is an object, so I cannot sort. Then I found this filter orderByObject , but after converting to an array, I would lose the object key.

Can the Firebase team help me improve this orderByObject filter to support an object key?

+7
angularjs angularjs-filter firebase angularfire
source share
2 answers

You can use orderByPriority to convert firebase objects to an array, and then apply a regular filter and orderBy.

  <div ng-repeat="customer in customers | orderByPriority | filter:searchText"> <span>{{ customer.$id }} </span> </div> 
+7
source share

Take a look at the source code of the orderByPriority filter - which converts the object into an array ordered by Firebase priority: https://github.com/firebase/angularFire/blob/master/angularfire.js#L37

You can include the object key directly in each element of the array by setting the special property $key .

+1
source share

All Articles