Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng switch创建了多少个手表?_Angularjs - Fatal编程技术网

Angularjs ng switch创建了多少个手表?

Angularjs ng switch创建了多少个手表?,angularjs,Angularjs,简单:ng交换了多少手表? 例如: <section ng-switch="value"> <div ng-switch-when="1">1</div> <div ng-switch-when="2">2</div> <div ng-switch-when="3">3</div> <div ng-switch-when="4">

简单:ng交换了多少手表?

例如:

    <section ng-switch="value">
        <div ng-switch-when="1">1</div>
        <div ng-switch-when="2">2</div>
        <div ng-switch-when="3">3</div>
        <div ng-switch-when="4">4</div>
    </section>
<pre>{{$$watchers.length - 1}}</pre>
<section ng-switch="value">
  <div ng-switch-when="1">...</div>
  ...
</section>

1.
2.
3.
4.
那会产生一块手表吗?四个


提前感谢。

ngSwitch
ng switch
属性中的表达式上创建一个观察者

一种简单的检查方法是在控制器中执行以下操作:

// $timeout is a crude way to "wait" until ng-switch sets up the watcher
$timeout(function(){
  console.log($scope.$$watchers ? $scope.$$watchers.length : 0);
})
另一个是这样做(减1是因为这个表达式引入了它自己的$watch):

{{$$watchers.length-1}
...
...
还有一个方法,就是去看一个
$scope.$watch
那里:)-当然,事实上没有孤立的作用域绑定

FWIW,这是一个很好的实时监视手表的工具。