angularfire - Digest is not triggered when scope variable is updated in AngularJS -
i using angularjs , angularfire show list of tasks:
<ul ng-repeat="tool in tools"> <li>{{tool.name}} {{ tool.description}}</li> </ul> var toolref = new firebase(dbref + "/tools/" + toolid); toolref.once('value', function(snapshot) { console.log(angular.tojson(snapshot.val())); $scope.tools.push(snapshot.val()); //$scope.$apply(); });
http://jsfiddle.net/oburakevych/5n9mj/11/
code simple: bind 'site' object firebase db. object contains list of id of relevant tools. load every tool in $scope.tools variable , use ng-repeat show them in ui. however, every time push new entry $scope.tools - dom not updated. have call $scope.$apply trigger digest after every push - see commented out line 18 , works.
it's strange since sow several times , scope variables bound angularfire.
can explain this? doing wrong?
because change scope outside of angularjs, must use $scope.$apply() inform angular scope changes. common way handle that. use error handling of angularjs wrap code in callback function like:
$scope.$apply(function(){ $scope.tools.push(snapshot.val()); });
Comments
Post a Comment