Hide and show form input element with a boolean value

Description

The following code shows how to hide and show form input element with a boolean value.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function Ctrl($scope) {<!--from w w  w.  jav  a2s  .  c om-->
  $scope.show = true;
  $scope.theField = '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="theField" />
     </span>
         <br/>
     Inputs outside of switch:
     <input type="text" data-ng-model="theField" />
         <br/>
     Values:
     {{theField}}
     </form>
</div>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities