ng-if

Description

ng-if removes or recreates an element in the DOM based on an expression.

ng-if is different from ng-show and ng-hide. ng-if removes and recreates DOM nodes, rather than just showing and hiding them via CSS.

Example

The following code shows how to ng-if.


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

  <div ng-if="2 + 2 === 5">
    No
  </div>

  <div ng-if="2 + 2 === 4">
    yes
  </div>

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

</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives