This is probably a bug in AngularFire:

problem:
The orderByPriority filter when applied in JS code does not filter a 
firebase object to an array containing just FB objects. The filter returns 
the same FB object passed in. The AngularFire 
docs<https://www.firebase.com/docs/angular/reference.html#orderbypriority>say 
this about it:

The orderByPriority filter is provided by AngularFire to convert an object 
returned by $firebase into an array. The objects in the array are ordered 
by priority (as defined in Firebase). Additionally, each object in the 
array will have a $id property defined on it, which will correspond to the 
key name for that object.

This is my code:

ref= $firebase(new Firebase(url));
console.log(ref);
                    $scope.todos = $filter("orderByPriority")(ref); 
//filter FB object to array
console.log($scope.todos);

//FireBug console:

Object { $bind=function(), $add=function(), $save=function(), more...}
Object { $bind=function(), $add=function(), $save=function(), more...}

>>>>>>>>>>>>>>>>>>>>>>>>>>>

When the orderByPriority filter is not applied in the controller butinstead 
applied in a view the data objects _do_ have the $id property injected:

//retrieve FB reference in controller:

$scope.todos = $firebase(new Firebase(url));


//display the items in view:

                <ul id="todoList" ng-cloak>
                    <li ng-repeat="todo in todos | orderByPriority">
                        <span ng-class="{'fa fa-check 
pointer':!todo.completed}" ng-click="completeTodo(todo)"></span>
                        <span ng-bind="todo.title" data-ref="{{todo.$id}}" 
ng-class="{strike:todo.completed}" ></span>
                        [....]


// button to remove items

                <button ng-click="removeCompleted()" >Verwijder 
voltooid</button>


// function removeCompleted() called by buttonclick

                    $scope.removeCompleted = function(){
                        ng.forEach($scope.todos,
                            function(todo){
                                if(typeof todo != "function" && 
todo.completed){
console.log(todo);
                                    [...]
                                }


// output in FireBug console:

Object { completed=true, title="444444", $id="-JG6JefXOPu_EZjkdRiq", more...
}

so it looks like the $id object is injected in FB data item _only_ when the 
orderByPriority filter is applied in the view. When applied in controller 
orderByPriority filter has no effect...

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to