typescript 离子条件类css

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44022439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:33:21  来源:igfitidea点击:

Ionic conditional class css

angulartypescriptionic-frameworkionic2ionic3

提问by Richard

I am using Ionic3, and have:

我正在使用 Ionic3,并且有:

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

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

我想class在填充另一个值时有条件地更改该值,即将ratingForm.controls.review.length > 0值更改为class="char-left-error".

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

我确实看过ng-class,但似乎无法让它发挥作用。

Any help appreciated.

任何帮助表示赞赏。

回答by sebaferreras

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 ngClassit would look like

通过使用ngClass它看起来像

<span class="char-left" [ngClass]="{'char-left-error' : ratingForm.controls.review.length > 0}">