14

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.

2
  • 1
    You should take another look at ng-class Commented May 17, 2017 at 10:36
  • if I do <span ng-class="char-left">, the class char-left is not even applied. Commented May 17, 2017 at 10:38

1 Answer 1

35

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}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.