Ionic conditional class css

末鹿安然 提交于 2019-12-22 03:21:47

问题


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.


回答1:


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}">


来源:https://stackoverflow.com/questions/44022439/ionic-conditional-class-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!