Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-if Directive

AngularJS ng-if Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

Uncheck and remove the content:

Keep the HTML:

<

input

type=

"checkbox"

ng-model=

"myVar"

ng-init=

"myVar = true"

<

div

ng-if=

"myVar"

<

h1

Welcome

<

/h1

<

p

Welcome to my home.

<

/p

<

hr

<

/div

Try it »


Definition and Usage

ng-if The directive is used to remove an HTML element when the expression is false.

If the result of the if statement is true, the element is added and displayed.

ng-if The directive differs from ng-hide. ng-hide hides the element, while ng-if removes the element from the DOM.


Syntax

<

element

ng-if=

"expression"

<

/element

All HTML elements support this directive.


Parameter value

Value Description
expression If the expression returns false, the entire element is removed; if true, the element is added.

AngularJS Reference Manual AngularJS Reference Manual