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.

http://jsfiddle.net/rv4lw/2/

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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -