muzi jack muzi jack - 6 months ago 52
AngularJS Question

i want to assign a snapshot.val() to to $scope variable $scope.pending and bind it to a ng-repeat list

firebase logged data

Object {information: "way", status: "pending", title: "killa"}
controllers.js:43 Object {information: "way", status: "pending", title: "killa"}
controllers.js:42 Object {information: "way", status: "pending", title: "killa2"}
controllers.js:43 Object {information: "way", status: "pending", title: "killa2"}




i dont seem to get the list of items im fetching from firebase but im able to log it.

<ion-list ng-controller="pendingTasksCtrl">
<ion-item ng-click="task.completed = !task.completed" class="item-icon-right" ng-repeat="p in pending">{{p.title}}{{p.information}}
<i class="icon ion-ios-arrow-left"></i>
<ion-option-button class="ion-trash-a" ng-click="removeItem($index,1)">
</ion-option-button>
<ion-option-button ng-controller="editTaskCtrl" class="ion-edit" ng-click="modal.show()">
</ion-option-button>
</ion-item>
</ion-list>


i want to assign snapshot to a $scope.pending and bind it on front end. but im getting an undefined error

.controller('pendingTasksCtrl', function($scope,$firebaseArray,$firebaseObject,$rootScope,$ionicModal)
{

var task = "AllTasks";
var id =0;

var itemref = new Firebase("https://tasksbylima.firebaseio.com/");
//$scope.items = $firebaseArray(itemref);
//var status = "completed";

$scope.test = function()
{
itemref.orderByChild("status").equalTo("pending").on("child_added", function(snapshot)
{
$scope.pending = snapshot.val();

console.log(snapshot.val());
console.log(pending);

// console.log("**************find me "+itemref.orderByChild("status").equalTo("task").on("child_added"));
});

}
})

Answer
var itemref = new Firebase("https://tasksbylima.firebaseio.com/task");
   var taskref = itemref.orderByChild("status").equalTo(true);
     taskref.on("value", function(response) {
     $scope.filterTasks = response.val();

That works perfectly

Comments