Causes an element and its contents to be conditionally added/removed from the DOM based on the value of the given boolean template expression.

For details, see the ngIf discussion in the Template Syntax page.

Examples

<hero-detail *ngIf="isActive"></hero-detail>
<div *ngIf="hero != null" >{{hero.name}}</div>
<div template="ngIf hero != null">{{hero.name}}</div>
<template [ngIf]="hero != null">
  <div>{{hero.name}}</div>
</template>
Annotations
  • @Directive(selector: '[ngIf]', inputs: const ['ngIf'], visibility: Visibility.none)

Constructors

NgIf(ViewContainerRef _viewContainer, TemplateRef _templateRef)

Properties

ngIf bool newCondition
Whether the content of the directive should be visible.
write-only
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(other) → bool
The equality operator. [...]
inherited