7
votes

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?

2

2 Answers

7
votes

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>
1
votes

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.