KnightB4
KnightB4

Reputation: 95

angular 2 how to add element property only if condition is met

With Angular 2, what is the syntax to add an element property only if a condition is met. I was thinking of using *ngIf but it just adds or removes the entire element.

Upvotes: 1

Views: 1098

Answers (1)

hholtij
hholtij

Reputation: 2936

Depends on the property. The general syntax is [property]="value or condition".

For example:

[class.myclass]="condition" [style.height]="value" [selected]="condition"

Where condition and value are javascript expressions. Google for "Angular 2 template syntax".

Upvotes: 2

Related Questions