Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A orderby object filter for a pure Firebase JavaScript API

I found angularFire is always confusing me when used in conjunction with the pure Firebase JavaScript API.

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

So I decide to use the Firebase JavaScript API alone because I realized it already has two-way data binding (explicit) with AngularJS without using angularFire.

Demo without ngFire

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

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

like image 640
vzhen Avatar asked Jan 15 '14 23:01

vzhen


2 Answers

You can use orderByPriority to convert firebase objects into array and then apply normal filter and orderBy.

 <div ng-repeat="customer in customers | orderByPriority | filter:searchText">
     <span>{{ customer.$id }} </span>
 </div>
like image 196
Fizer Khan Avatar answered Nov 15 '22 09:11

Fizer Khan


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

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

like image 42
Anant Avatar answered Nov 15 '22 09:11

Anant