How does data binding work in AngularJS?

前端 未结 14 1506
情话喂你
情话喂你 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:15

    Explaining with Pictures :

    Data-Binding needs a mapping

    The reference in the scope is not exactly the reference in the template. When you data-bind two objects, you need a third one that listen to the first and modify the other.

    Here, when you modify the , you touch the data-ref3. And the classic data-bind mecanism will change data-ref4. So how the other {{data}} expressions will move ?

    Events leads to $digest()

    Angular maintains a oldValue and newValue of every binding. And after every Angular event, the famous $digest() loop will check the WatchList to see if something changed. These Angular events are ng-click, ng-change, $http completed ... The $digest() will loop as long as any oldValue differs from the newValue.

    In the previous picture, it will notice that data-ref1 and data-ref2 has changed.

    Conclusions

    It's a little like the Egg and Chicken. You never know who starts, but hopefully it works most of the time as expected.

    The other point is that you can understand easily the impact deep of a simple binding on the memory and the CPU. Hopefully Desktops are fat enough to handle this. Mobile phones are not that strong.

提交回复
热议问题