0

In AngularJS the data-binding work to expose immediate data to our View !! this stuff's due of the object scope which is the glue between the Logic Code AND The View. Also all we know that AngularJs support the tow-way-binding !!! My Question Is :

How the $scope can know that there object binding was changed or not??
if there while condition inside scope for auto-change detect or what?
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720

1 Answers1

0

Check angular.js file, we will get the code for ngBindDirective:

var ngBindDirective = ['$compile', function($compile) {
  return {
    restrict: 'AC',
    compile: function ngBindCompile(templateElement) {
      $compile.$$addBindingClass(templateElement);
      return function ngBindLink(scope, element, attr) {
        $compile.$$addBindingInfo(element, attr.ngBind);
        element = element[0];
        scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
          element.textContent = isUndefined(value) ? '' : value;
        });
      };
    }
  };
}];

Note the last two line, it used watcher for attribute ngBind, for any change it apply to the element.

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85