0

I'm trying to learn angular with firebase. I'm getting data and successfully output it. But after this, simple filters not working with this data. When i'm doing simple $http.get from the same, but local json file, filters works just fine. My application module/controller code:

var app = angular.module('testSite', ['ngRoute', 'angControllers', 'firebase'])
.value('fbURL', 'https://sizzling-fire-3696.firebaseio.com/')
.factory('personData', function($firebase, fbURL) {
    return $firebase(new Firebase(fbURL));
});
app.controller("angCont", ['$scope', '$http', '$routeParams',
 'personData', 
    function($scope, $http, $routeParams, personData) {
        $scope.data = personData;
}]);

And this is my html template:

<div ng-controller="angCont">
    <select ng-model="personSelectFilter" ng-options="person.name for person in data">
        <option value="">Filter by name</option>
    </select>
    <input type="text" ng-model="personInputFilter" placeholder="Filter">
    <ul>
    <li ng-repeat="person in data | filter: personInputFilter |
     filter: personSelectFilter | orderBy: personSorting">
    Name: <a href="#/persons/{{person.name}}">{{person.name}}</a><br/>
    Surname: {{person.surname}}<br/>
    Age: {{person.age | number}}<br/>
    Experience (months): {{person.exp | number}}</li>
    </ul>
</div>

http://angulartest.hostoi.com/angsite.html#/

5
  • Can you show a link? That definitely should not be happening. Commented Feb 18, 2014 at 20:41
  • I'm trying it on localserver. Or stuff like that is not supposed to work on localhost? Commented Feb 18, 2014 at 20:43
  • Well, its client side, so it should work the same regardless. Commented Feb 18, 2014 at 20:46
  • All i can say, that data from firebase loading with delay about 0.5-1 second. But it's loads only in ng-repeat ul-li. Select with ng-options is empty like nothing happend. And simpliest input filters not working too. Commented Feb 18, 2014 at 20:50
  • angulartest.hostoi.com/angsite.html# - demo on freehosting site Commented Feb 18, 2014 at 20:58

1 Answer 1

5

$firebase always creates an object, so the data variable contains key/value pairs. However, filter and orderBy in Angular expect an array. This can be corrected by using orderByPriority, which is covered in the AngularFire docs under Ordered Data and Arrays.

<li ng-repeat="person in data | orderByPriority | filter: personInputFilter |
    filter: personSelectFilter | orderBy: personSorting">
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, that is what i needed! Thank you, i definitely was googling wrong questions about filters and other stuff.
It should probably be part of the angularFire tutorial or getting started guide.
wow that is a long filter chain. No prob for learning, but be careful with those digest permutations.

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.