AngularJS Tutorial - ng-show/ng-hide








ng-show and ng-hide show or hide the HTML element based its expression.

The show or hide is controlled by the ng-hide CSS class.

The .ng-hide CSS class is predefined in AngularJS and sets the display style to none.

Example

The following code shows how to ng-show/ng-hide.


<!--from  www.  ja  va  2s  . c o m-->

<!doctype html>
<html ng-app="myApp">
<head>
  <link rel="stylesheet" href="http://cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>

  <div ng-show="2 + 2 == 5">don't show</div>
  <div ng-show="2 + 2 == 4">show</div>

  <div ng-hide="2 + 2 == 5">don't hide</div>
  <div ng-hide="2 + 2 == 4">do hide</div>

  <script>
    angular.module('myApp', []);
  </script>

</body>
</html>

The code above is rendered as follows: