How does data binding work in AngularJS?

前端 未结 14 1538
情话喂你
情话喂你 2020-11-21 05:41

How does data binding work in the AngularJS framework?

I haven\'t found technical details on their site. It\'s more or less clear how it works when data

14条回答
  •  悲&欢浪女
    2020-11-21 06:08

    This is my basic understanding. It may well be wrong!

    1. Items are watched by passing a function (returning the thing to be watched) to the $watch method.
    2. Changes to watched items must be made within a block of code wrapped by the $apply method.
    3. At the end of the $apply the $digest method is invoked which goes through each of the watches and checks to see if they changed since last time the $digest ran.
    4. If any changes are found then the digest is invoked again until all changes stabilize.

    In normal development, data-binding syntax in the HTML tells the AngularJS compiler to create the watches for you and controller methods are run inside $apply already. So to the application developer it is all transparent.

提交回复
热议问题