' Use strict 'App.controller (function($scope) { =null; function () { wx.chooseimage ({ sourcetype: [], success:function(res) { =1}}) ;
< p ng-click= "chooseimage ()">{{aaaa}}</p>
After clicking on the page AAAA value will not change to 1
Because Wx.chooseimage this method is the API, not in the angular context, does not call the Apply method.
$apply method Usage Scenario: AngularJS external Controllers (DOM events, external callback functions such as jQuery UI space, and so on) must call $apply after the AngularJS function is called. In this case, you need to command AngularJS to refresh itself (model, view, etc.), $apply is used to do this thing.
before I saw my colleague write a $timeout (function () {}) is good, is also curious. Originally angular in the $timeout method has encapsulated the Apply method.
I mainly read these two articles:
Talk about angular about $watch, $apply and how $digest works
"AngularJS"----$apply and $watch
AngularJS Why I changed the value of the variable in the controller, DOM has not changed