AngularJS Why I changed the value of the variable in the controller, DOM has not changed

Source: Internet
Author: User

' 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.