How to load X chat messages in typescript?

Viewed 30

I'm making a web chat application with ionic, and I'm having trouble with how many messages I show/load. My code to load the messages from the database is this:

<ion-item *ngFor="let mesage of messages | slice: 0:slice" class="msg">
      <ion-row>
        <ion-text color="tertiary"><b>{{ mesage.user }}: &nbsp;</b></ion-text>
        <ion-text color="secondary"> {{ mesage.text }}</ion-text>
      </ion-row>
    </ion-item>

With this, I load from the first message on the database to message[slice], and when I load more items, I just augment slice's valor, but what I don't know what to do is to only load, for example, the last 10 messages and then load the new ones when they come

1 Answers

If anyone got the same problem, I just loaded the messages from an index (depending on how many msg there are, it's size varies) like this: *ngFor="let message of messages | slice: ind:messages.length" (When pushing a new message, it needs to do ind-- to add 1 more message, otherwise it doesn't show the first message that was loaded there)

Related