Currently, using Angular 4, I'm attempting to utilize ngClass by comparing a variable called sender
which is created within a function with an object from an array known as item.sender
.
Below is the snippet of HTML code:
<ion-card *ngFor="let item of items" [ngClass]="{'me': item.sender == sender, 'notme': item.sender != sender}">
<ion-card-header>
@{{item.sender}}
</ion-card-header>
<ion-card-content>
{{item.message}}
</ion-card-content>
</ion-card>
The function containing the variable sender
looks like this:
send(desc: string) {
console.log("message:", desc);
var listkey = this.listKey;
var user = firebase.auth().currentUser;
var uid = user.uid;
var email = user.email;
var sender = email.substring(0, email.lastIndexOf("@"));
var messagecontent = {
message: this.messagecontent,
sender: sender,
};
firebase.database().ref('userlists' + '/' + listkey + '/' + 'chat').push(messagecontent);
this.messagecontent = '';
}
I'm wondering if this can be achieved and if so, what might I be overlooking?