352229 (9) [Avatar] Offline
#1
I have read that ng-model - binds the value of HTML controls (input, select, textarea) to application data. Now in the code
<input type="text" ng-model="name"></p>
. How does that work behind the scenes
Lukas Ruebbelke (107) [Avatar] Offline
#2
ng-model basically hooks into the Angular digest cycle so that a digest cycle is kicked off when the value of the input changes. Please let me know if you would like me to elaborate further.
352229 (9) [Avatar] Offline
#3
Hi Lukas

Thanks for the reply. When I say Digest cycle and ng-model does it mean that dirty checking is done. For example if we have a textbox and a span tag. In the textbox I have added an attribute ng-model = 'name' and in the span I have put {{name}}. So angular.js will do dirty checking i.e. checks if the value of textbox is same as previous value. If not then it updates span as well.

Thanks
Lukas Ruebbelke (107) [Avatar] Offline
#4
That is correct. Angular detects that the value in the text input is 'dirty' and kicks of a digest cycle to synchronize everything.