ng-if in angularjs

  • We can also use and (&&) or (||) operator in ng-if to evaluate the expression.
  • If ng-if evaluates to a false it will remove from the DOM element and if it is true, then element is reinserted into the DOM.
  • We can also use nested ng-if in angularjs.
  • Ng-if directive is condition based directive which removes or recreates the DOM portion according to condition.
  • Now executes the code and you will get following output

ng-if directive in angularjs is used to check condition. in this artical i have discussed ng-if with example.

@techaltum: ng-if in angularjs with example

Ng-if directive is condition based directive which removes or recreates the DOM portion according to condition. It evaluates expression as true or false. If ng-if evaluates to a false it will remove from the DOM element and if it is true, then element is reinserted into the DOM.

In the following example I want to take textbox value and accordingly I want to print whether it is even or odd. So we will write code in the following manner

Now executes the code and you will get following output

We can also use and (&&) or (||) operator in ng-if to evaluate the expression. We can also use nested ng-if in angularjs.

ng-if in angularjs