Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic conditional class css

I am using Ionic3, and have:

<span class="char-left">{{REVIEW_MAX_LENGTH-ratingModel.review.length}} characters left</span>

I would like to conditionally change the class value when another value is populated, i.e when ratingForm.controls.review.length > 0 change the values to class="char-left-error".

I did look at ng-class, but cannot seem to get it to work.

Any help appreciated.

like image 421
Richard Avatar asked May 17 '17 10:05

Richard


1 Answers

If it's just a single class, you can try with

<span class="char-left" [class.char-left-error]="ratingForm.controls.review.length > 0">

By using ngClass it would look like

<span class="char-left" [ngClass]="{'char-left-error' : ratingForm.controls.review.length > 0}">
like image 110
sebaferreras Avatar answered Sep 26 '22 04:09

sebaferreras