angularjs - Scope changes after ng-switch -
i have switch changes value of variable called p.
<div ng-switch on="p"> <div ng-switch-when="true"> /*...show nodes , ability add node*/ </div> <div ng-switch-when="false"> /*for show nothing*/ </div> </div>
in controller:
$scope.nodes=[{node1},{node2},{node3}]; function add node $scope.$watch('nodes', function(nodes) { console.log(nodes); console.log("================"); },true);
problem: when print $scope nodes in above new nodes shown. if switch off , on (p=false , p=true) have initial $scope.nodes. why on earth nodes reset on switch? see example: plunker
edit: ng-switch worked no scope change if didn't have directive reinitialized scope when used directive inside it. although haven't understood why dropped ng-switch , used ng-show instead.
it see controller , on level initialized. ngswitch not hide content - remove , add html , initialize controllers , directives each time switch made. nodes initialized there well.
Comments
Post a Comment