I want to change my classe for an element but I don't know how to process with Ionic 2. I tried this way but it's wrong :
<span [ngClass]="{(user.id == this.session.userDefaultId) : 'class1 class2', (user.id != this.session.userDefaultId) : 'class3 class4'}">
...
</span>
Someone can explain me how to do somethink like that please ? :)
You can use a simple ternary operator to set the class for your example.
<span [ngClass]="(user.id == this.session.userDefaultId) ? 'class1 class2' : 'class3 class4'">
...
</span>
You have to mention the class name first followed by the condition
<span [ngClass]="{'class1 class2' : (user.id == this.session.userDefaultId), 'class3 class4':(user.id != this.session.userDefaultId)}">
...
</span>
try this
<span [class.class1]="user.id == this.session.userDefaultId" [class.class2]="user.id == this.session.userDefaultId" [class.class3]="user.id != this.session.userDefaultId" [class.class4]="user.id != this.session.userDefaultId">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With