data-ng-switch to control if to display

Description

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) {<!--from   ww w .j a v a 2 s .c  om-->
  $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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities