I'm following a tutorial at https://angular-meteor.com/tutorials/whatsapp2/ionic/chats-page for an Ionic 2 application. I receive an error when I add the following code:
removeChat(chat: Chat): void {
this.chats = this.chats.map<Chat[]>(chatsArray => {
const chatIndex = chatsArray.indexOf(chat);
chatsArray.splice(chatIndex, 1);
return chatsArray;
});
}
This function is being called on a click event on the button with class "option-remove"
<ion-content class="chats-page-content">
<ion-list class="chats">
<ion-item-sliding *ngFor="let chat of chats | async">
<button ion-item class="chat">
<img class="chat-picture" [src]="chat.picture">
<div class="chat-info">
<h2 class="chat-title">{{chat.title}}</h2>
<span *ngIf="chat.lastMessage" class="last-message">
<p *ngIf="chat.lastMessage.type == 'text'" class="last-message-content last-message-content-text">
{{chat.lastMessage.content}}
</p>
<span class="last-message-timestamp">{{chat.lastMessage.createdAt | amCalendar }}</span>
</span>
</div>
</button>
<ion-item-options class="chat-options">
<button ion-button color="danger" class="option option-remove" (click)="removeChat(chat)">Remove</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
Not sure how accurate the error message is but it seems to have a problem with the line this.chats.map<Chat[]>(chatsArray => {.
this.chatsis an array of objects or arrays?