Issue
New to Ionic and Angular, but hope someone can help me out.
I have the following data:
"messages" : [
{
"sender" : "24",
"name" : "James",
"datetime" : ISODate("2019-11-10T20:42:02.090Z"),
"message" : "test 1",
"read" : [
{
"uid" : "24",
"name" : "James",
"datetime" : ISODate("2019-11-10T20:42:02.090Z")
},
{
"uid" : "45",
"name" : "Paul",
"datetime" : ISODate("2019-11-13T11:32:45.010Z")
}
]
}]
In ionic, I currently have (data is being passed as 'mailbox' and 'uid' is the id of the user)
<ion-item *ngFor="let message of mailbox">
<ion-item [routerLink]="['/members/mailbox', message.sid" routerDirection="forward">
{{ message.name}}
<br />Posted: {{ message.datetime }}
<div *ngIf="(message.read[0]['uid'] == uid || message.read[1]['uid'] == uid)">READ</div>
</ion-item>
</ion-item>
What i'm after is a better way to write the ngIf, for instance the messages.read can have multiple rows. Is there a way just to check if the value for uid is found in messages.read? I had a play with the angular filter contains, but had no success.
Many thanks
Solution
It's better to leave hard work to .ts file.
You can use something like this;
in your .ts file;
validateId(message: Object) {
return message["read"].find(x => x.uid === uid);
}
and in .html;
<ion-item *ngFor="let message of mailbox">
<ion-item [routerLink]="['/members/mailbox', message.sid" routerDirection="forward">
{{ message.name}}
<br />Posted: {{ message.datetime }}
<div *ngIf="validateId(message)">READ</div>
</ion-item>
</ion-item>
Answered By - Fulya D.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.