diff --git a/modules/@angular/common/src/directives/ng_if.ts b/modules/@angular/common/src/directives/ng_if.ts index 9d8f42f36a..ddecc54d06 100644 --- a/modules/@angular/common/src/directives/ng_if.ts +++ b/modules/@angular/common/src/directives/ng_if.ts @@ -6,46 +6,152 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; +import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef} from '@angular/core'; + /** - * Removes or recreates a portion of the DOM tree based on an {expression}. + * Conditionally includes a template based on the value of an `expression`. * - * If the expression assigned to `ngIf` evaluates to a falsy value then the element - * is removed from the DOM, otherwise a clone of the element is reinserted into the DOM. + * `ngIf` evaluates the `expression` and then renders the `then` or `else` template in its place + * when expression is thruthy or falsy respectively. Typically the: + * - `then` template is the inline template of `ngIf` unless bound to a different value. + * - `else` template is blank unless its bound. * - * ### Example ([live demo](http://plnkr.co/edit/fe0kgemFBtmQOY31b4tw?p=preview)): + * # Most common usage + * + * The most common usage of the `ngIf` is to conditionally show the inline template as seen in this + * example: + * {@example common/ngIf/ts/module.ts region='NgIfSimple'} + * + * # Showing an alternative template using `else` + * + * If it is necessary to display a template when the `expression` is falsy use the `else` template + * binding as shown. Note that the `else` binding points to a `