Stats

389 Contributors: 4 Wednesday, August 2, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

How to Use ngif

Introduction

*NgIf: It removes or recreates a part of DOM tree depending on an expression evaluation. It is a structural directive and structural directives alter the layout of the DOM by adding, replacing and removing its elements.

Syntax

  • <div *ngIf="false"> test </div> <!-- evaluates to false -->
  • <div *ngIf="undefined"> test </div> <!-- evaluates to false -->
  • <div *ngIf="null"> test </div> <!-- evaluates to false -->
  • <div *ngIf="0"> test </div> <!-- evaluates to false -->
  • <div *ngIf="NaN"> test </div> <!-- evaluates to false -->
  • <div *ngIf=""> test </div> <!-- evaluates to false -->
  • All other values evaluate to true.

Related Examples