AngularFire Filtering Data Returned by Firebase
<input type="text" class="form-control" ng-model="storeSearch.$" placeholder="Store Search">
<ul class="list-unstyled" ng-repeat="store in stores | orderByPriority | filter:storeSearch">
<li><a href="#/stores/{{store.name}}/" class="btn btn-danger btn-lg">{{store.name}}<br/>{{store.address}}</a></li>
</ul>
<script>
angular.module('myApp.controllers', [])
.controller('StoresController', ['$scope', '$firebase', function($scope, $firebase) {
var ref = new Firebase('https://MYFIREBASE.firebaseio.com/stores/');
$scope.stores = $firebase(ref);
}])
</script>
In my Controller I access the list of stores using Firebase and $firebase. At this point my $scope has the list of stores with some methods used by AngularFire to update data. The partial above will render the list just fine but without orderByPriority the search filter would not work. The orderByPriority converts an object returned by $firebase into an array. This array will work with any normal AnguarJS filter.
Here is the definition from the API of AngularFire.
TheThat's all there is to it. I hope this helps someone else figure out this problem as I spent a long time trying to get my filter to work with Firebase objects.orderByPriorityfilter is provided by AngularFire to convert an object returned by$firebaseinto an array. The objects in the array are ordered by priority (as defined in Firebase). Additionally, each object in the array will have a$idproperty defined on it, which will correspond to the key name for that object.
Comments
Join the discussionNo comments yet. Be the first to comment.




