Zero observers in the directive if one-time binding is used in angular 1.3+

I made a directive user-namefor this question

.directive('userName', function($http) {
  return {
    restrict: 'E',
    scope: {
      user: '='
    },
    replace: true,
    template: '<div><span ng-bind="user.username"></span> <a ng-if="user.active">Add</a></div>',
  };
});

It is important that the directive uses the minimum number of hours when I use a one-time binding to a user attribute ( <user-name user="::user"></user-name>).

I have a number of questions. I created this plunker to check my directive.

  • Why are there observers in a one-time event, although userit will not be updated?
  • Can I go to zero observers in this directive when using a one-time binding?
  • , $watch DOM - , , . $watch?
0
1

getWatchers ( ). $$postDigest .

, .

, :

{isolateScope: Array[2], scope: Array[1]}

: user.username user.active:

<div><span ng-bind="user.username"></span> <a ng-if="user.active">Add</a></div>

: {{$index}}:

<li ng-repeat="user in users" id="user_a_{{$index}}">

, .

$watch?

, , - DOM, , .

$ , .

  var unwatch = scope.$watch('oneTime', function (newVal, oldVal) {
     unwatch();
     ...
  });

" , ".

scope.$watch(function () { return globalVar }, function () { scope.scopeVar = ... });
+3

All Articles