Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular : how to express condition in ng-if directive?

Tags:

How to express a condition in ng-if directive ?

Right now I tried this

<div ng-if="{ selectedTab == 'decoupage'}"> ... Syntax Error: Token '==' is unexpected, expecting [:] at column 15 of the expression [{ selectedTab == 'decoupage'}] starting at [== 'decoupage'}]. 

I'm using Angular 1.2.0.

like image 767
Mat Avatar asked Nov 11 '13 14:11

Mat


People also ask

How do you use multiple conditions in Ng-if?

We can use multiple conditions in *ngIf with logical operator AND (&&) to decide the trustworthy of *ngIf expression. If all conditions are true, then element will be added to the DOM.

What is * ngIf Angular?

A shorthand form of the directive, *ngIf="condition" , is generally used, provided as an attribute of the anchor element for the inserted template. Angular expands this into a more explicit version, in which the anchor element is contained in an <ng-template> element.

What is the use of NG-if directive?

Definition and Usage The ng-if directive removes the HTML element if the expression evaluates to false. If the if statement evaluates to true, a copy of the Element is added in the DOM.


1 Answers

ng-if is already in an angular context so you can just do this:

ng-if="selectedTab == 'decoupage'" 

For future reference:

  • double curly braces: {{ }} -> are for interpolation
  • single curly braces: { } I've only seen in ng-class for boolean expression resolution.
like image 154
Davin Tryon Avatar answered Sep 27 '22 19:09

Davin Tryon