angularjs - Two way binding doesn't work, need to call $apply to make it work -
env:
attempted in angular1.0.5, 1.1.2
issue:
my 2 way binding doesn't update view , have call $scope.$apply after $scope.is_pic setter in order see reflected in browser.
upload pic, see file input reflects file name. type text box above, calls $digest on ng-model , magically browser updated in controller.
if update "if" statement to:
if (e.target.result.indexof('data:image') !== -1) { $scope.apc.is_pic = true; return $scope.$apply(); } else { $scope.apc.is_pic = false; return $scope.$apply(); }
you'll see work. why failing me?
note: javascript generated coffeescript why looks awesome.
it's because model update done inside callback, i.e. not in angular context. 2 way binding works when model variables updated inside angular, otherwise should explicitly call $apply method.
Comments
Post a Comment