AngularJS ng-if Instruction
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
<
pWelcome to my home.
<
/p
<
hr
<
/divTry 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"
<
/elementAll 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