I am using Ionic 2, and have the following html code:
<ion-content padding class="messages-page-content">
<ion-scroll scrollY="true" class="messages">
<ion-list>
<ion-item class="message-item" *ngFor="let item of firelist | async">
<div [class]="'message message-me'">
<div class="message-content">{{item.message_text}}</div>
<span class="time-tick">
<span class="message-timestamp">{{item.timestamp | amDateFormat: 'DD MMM YYYY h:mm a'}}</span>
<div *ngIf="showTick(message) === true">
<span class="checkmark">
<div class="checkmark_stem"></div>
<div class="checkmark_kick"></div>
</span>
</div>
</span>
</div>
</ion-item>
</ion-list>
</ion-scroll>
</ion-content>
If you look at this line in particular:
<div [class]="'message message-me'">
I would like to be able to dynamically change the class.
For example, something like this, but I cannot get this to work:
<div [class]="{{item.memberId === me.memberId ? 'message message-me' : 'message message-you'}}">
Where me is defined in the supporting ts file.
Any advise welcome.
UPDATE
Based on the advise below outlined here, I try the following:
<div [class]="{'message message-me' : (item.uid == me.uid), 'message message-you':(item.uid === you.uid)}">
Now, I just lose all my formatting but no errors. Objects item.uid and me.uid do exist.
Original code:
<div [class]="'message message-me'">
UPDATE
The following kind of works:
<div [ngClass]="{'message message-you':(item.uid === you.uid), 'message message-me':(item.uid === me.uid)}">
I have a list where both conditions are met, but only the right hand condition is applying the style. If I swap the left and right conditions around, the other style works, so this suggests nothing is wrong with the data, but rather the html.
If I change it to:
<div [ngClass]="{'message message-me':(item.uid === me.uid), 'message message-you':(item.uid === you.uid)}">
I get:
I also try:
<div [ngClass]="{'message message-me':(item.uid != you.uid), 'message message-you':(item.uid === you.uid)}">
To prove it's not a problem with the data, but only the right hand class is ever applied.



