angularjs - How many watches ng-switch creates? -
simple: how many watches ng-switch place?
for example:
<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> will create 1 watch? four?
thanks in advance.
ngswitch creates single watcher on expression in ng-switch attribute.
one easy way check following in controller:
// $timeout crude way "wait" until ng-switch sets watcher $timeout(function(){ console.log($scope.$$watchers ? $scope.$$watchers.length : 0); }) another, (minus 1 because expression introduces own $watch):
<pre>{{$$watchers.length - 1}}</pre> <section ng-switch="value"> <div ng-switch-when="1">...</div> ... </section> and yet another, going source , seeing single $scope.$watch there :) - and, of course, fact there no isolate scope bindings
Comments
Post a Comment