I'm quite new to AngularJS, just started with it and I came across ng-switch
, where I noticed that this works only on <div>
tag, like
<div ng-app="myApp" ng-controller="switchController">
<div ng-switch on="myData.text">
<p ng-switch-when="1">Switch To 1</p>
<p ng-switch-when="2">Switch To 2</p>
<p ng-switch-default>Switch To Default</p>
</div>
</div>
when I declare it as below it throws an error!
<div ng-app="myApp" ng-controller="switchController">
<p ng-switch on="myData.text">
<p ng-switch-when="1">Switch To 1</p>
<p ng-switch-when="2">Switch To 2</p>
<p ng-switch-default>Switch To Default</p>
</p>
</div>
JavaScript :
angular.module("myApp", [])
.controller("switchController", function($scope) {
$scope.myData = {};
$scope.myData.text = 2;
console.log($scope.myData.text);
});
Hello one
Hello two
` works good. Why do you say nested `` are not valid?
– yashhy Sep 18 '14 at 06:01