我正在使用 Ionic2,并且有 ion-content
标签。根据变量,我想更改标签上的样式。
我已经尝试了以下方法,但它不起作用:
<ion-content *ngIf="persoModel.type === 0" padding class="person-content-wanted">
<ion-content *ngIf="personModel.type === 1" padding class="person-content-offered">
...
</ion-content>
任何人都可以提出实现此目标的方法吗?
谢谢
最佳答案
这里 personModel
是一个 bool 值,如果它是 true,你将得到 person-content-wanted
类,如果它是 false,你将得到 person-content-offerred
<ion-content [class]="personModel? 'person-content-wanted' : 'person-content-offered'">
关于CSS改变样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40671235/