AngularJS Tutorial - data-ng-switch to control if to display








The following code shows how to use data-ng-switch to control if to display.

Example


<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script type='text/javascript'>
function Ctrl($scope) {<!--  w  ww  . j  av  a2 s . c  o m-->
  $scope.show = true;
    $scope.field = {theText: 'hello'};
}
</script>
</head>
<body>
  <div ng:app>
 <form name="myForm" ng-controller="Ctrl">
 Inputs inside switch:
 <span data-ng-switch="show">
     <input data-ng-switch-when="true" type="text" data-ng-model="field.theText" />
 </span><br/>
 Inputs outside of switch:
 <input type="text" data-ng-model="field.theText" /><br/>
 Values:{{field.theText}}
 </form>
</div>
</body>
</html>

The code above is rendered as follows: