javascript - Ionic list + firebase binding not working -
i building app ionic , firebase. have firebasearray contains events date on server side.
i able sort these events on client side date.
the goal populate ion-list these events , sort them date (today, week, later).
the problem after retrieving events, sort them in local $scope.arrays date populate ion-list. since not firebasearrays anymore, there no binding between data , lists. (work after retrieving events if add event firebasearray, won't show in ion-list).
does can me how deal it? don't need actual code more way of thinking , maybe angularfire methods unaware.
here service using:
angular.module('starter.services', ['firebase']) .factory('soirees', function($firebase, $firebasearray) { var soireesref = new firebase('https://partey.firebaseio.com/soirees'); var soirees = $firebasearray(soireesref); return { all: function() { return soirees; }, add: function(soiree) { soirees.$add(soiree); }, remove: function(soiree) { soiree.$remove(soiree); }, get: function(soiree) { return soirees.$getrecord(soiree); } }; });
and here controller:
.controller('eventsctrl', function($scope, $state, $ionicloading, soirees) { $scope.soirees = soirees.all(); $scope.soireeday = []; $scope.soireeweek = []; $scope.soireefurther = []; var currentdate = new date(); $scope.soirees.$loaded().then(function() { angular.foreach($scope.soirees, function(soiree){ if (math.abs(currentdate - soiree.date) <= 1000*60*60*24) { $scope.soireeday.push(soiree); } else if (math.abs(currentdate - soiree.date) > 1000*60*60*24 && math.abs(soiree.date - currentdate) <= 7*1000*60*60*24) { $scope.soireeweek.push(soiree); } else { $scope.soireefurther.push(soiree); } }) $scope.soireedaynumber = $scope.soireeday.length; $scope.soireeweeknumber = $scope.soireeweek.length; $scope.soireefurthernumber = $scope.soireefurther.length; }) })
edit: using following filter:
.filter('soireeday', function() { return function(item) { var currentdate = new date(); console.log(currentdate); if (math.abs(currentdate - item.date) <= 1000*60*60*24) { return true } else { return false }} })
in html file: ng-repeat="soiree in soirees | filter:soireeday"
but looks liker filter not called. hint ?
thank all,
arnaud
Comments
Post a Comment