EVOLUTION-MANAGER
Edit File: ngIf.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/directive/ngIf.js?message=docs(ngIf)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ng/directive/ngIf.js#L3' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">ngIf</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> - directive in module <a href="api/ng">ng</a> </li> </ol> </header> <div class="api-profile-description"> <p>The <code>ngIf</code> directive removes or recreates a portion of the DOM tree based on an {expression}. If the expression assigned to <code>ngIf</code> evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.</p> <p><code>ngIf</code> differs from <code>ngShow</code> and <code>ngHide</code> in that <code>ngIf</code> completely removes and recreates the element in the DOM rather than changing its visibility via the <code>display</code> css property. A common case when this difference is significant is when using css selectors that rely on an element's position within the DOM, such as the <code>:first-child</code> or <code>:last-child</code> pseudo-classes.</p> <p>Note that when an element is removed using <code>ngIf</code> its scope is destroyed and a new scope is created when the element is restored. The scope created within <code>ngIf</code> inherits from its parent scope using <a href="https://github.com/angular/angular.js/wiki/Understanding-Scopes#javascript-prototypal-inheritance">prototypal inheritance</a>. An important implication of this is if <code>ngModel</code> is used within <code>ngIf</code> to bind to a javascript primitive defined in the parent scope. In this case any modifications made to the variable within the child scope will override (hide) the value in the parent scope.</p> <p>Also, <code>ngIf</code> recreates elements using their compiled state. An example of this behavior is if an element's class attribute is directly modified after it's compiled, using something like jQuery's <code>.addClass()</code> method, and the element is later removed. When <code>ngIf</code> recreates the element the added class will be lost because the original compiled state is used to regenerate the element.</p> <p>Additionally, you can provide animations via the <code>ngAnimate</code> module to animate the <code>enter</code> and <code>leave</code> effects.</p> </div> <div> <h2>Directive Info</h2> <ul> <li>This directive creates new scope.</li> <li>This directive executes at priority level 600.</li> </ul> <h2 id="usage">Usage</h2> <div class="usage"> <ul> <li>as attribute: <pre><code><ANY ng-if=""> ... </ANY></code></pre> </li> </div> <h2 id="animations">Animations</h2> <p>enter - happens just after the <code>ngIf</code> contents change and a new DOM element is created and injected into the <code>ngIf</code> container leave - happens just before the <code>ngIf</code> contents are removed from the DOM</p> <a href="api/ngAnimate/service/$animate">Click here</a> to learn more about the steps involved in the animation. <section class="api-section"> <h3>Arguments</h3> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> ngIf </td> <td> <a href="" class="label type-hint type-hint-expression">expression</a> </td> <td> <p>If the <a href="guide/expression">expression</a> is falsy then the element is removed from the DOM tree. If it is truthy a copy of the compiled element is added to the DOM tree.</p> </td> </tr> </tbody> </table> </section> <h2 id="example">Example</h2><p> <div> <a ng-click="openPlunkr('examples/example-example82')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example82" module="ngAnimate" deps="angular-animate.js" animations="true"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code>Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /><br/> Show when checked: <span ng-if="checked" class="animate-if"> This is removed when the checkbox is unchecked. </span></code></pre> </div> <div class="runnable-example-file" name="animations.css" language="css" type="css"> <pre><code>.animate-if { background:white; border:1px solid black; padding:10px; } .animate-if.ng-enter, .animate-if.ng-leave { -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; } .animate-if.ng-enter, .animate-if.ng-leave.ng-leave-active { opacity:0; } .animate-if.ng-leave, .animate-if.ng-enter.ng-enter-active { opacity:1; }</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example82/index.html" name="example-example82"></iframe> </div> </div> </p> </div>