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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -