0

Question in short:

What is the best way to show comments in ionic2, especially when it has replies. I need to show replies based on their time.

++++++++++++++++++++++++++++++

Question in detail:

I have the below data with me in json format.

This is the list of comments. In this example 19 comments are there under items tag.

http://www.jsoneditoronline.org/?id=47b282c498505ed25869dc36f5f3bd58

Comments are already sorted based on Date published.

Now on the Item Id 10th there are two replies to this comment.

I am looking for a way to order this reply based on publishedAt time.

Below is my html: Here videoComments = the json data specified above

I tried using angualr-pipes orderBy pipe but that did not work for me, is there any alternative way?

<ion-list>
  <ion-item *ngFor="let comment of videoComments">
    <!-- here i Print the details what is required , next if there are any reply i would like to show them-->   
    <div *ngIf="comment.snippet.totalReplyCount != 0">
      <ion-list>
        <ion-item *ngFor="let reply of comment.replies.comments | orderBy: 'publishedAt'"> 
          <!-- Above orderBy pipe is not working , may be my syntax is wrong -->
           <!-- I would like to show replies in ascending order of when it was submitted-->
          <!-- Details of replies will be shown here -->          
        </ion-item>
      </ion-list>
    </div>
  </ion-item>
</ion-list>
kboul
  • 13,836
  • 5
  • 42
  • 53
just10minutes
  • 583
  • 10
  • 26
  • I don't know if it can help you, but try using MomentJS and convert your date to Unix time, this way it'll be a number like 1499560680 so a simple sort before displaying could do the trick – Gabriel Barreto Jul 09 '17 at 03:39
  • @Gabriel, Thank you for your suggestion. What I believe is OrderBy Pipe is not getting applied at all in any of the tags no matter which tag I use. Because when I did orderBY: '-publishedAt' there was no difference in the result. – just10minutes Jul 09 '17 at 12:24
  • You can use lodash to order them – Colonel Mustard Jul 09 '17 at 19:36

1 Answers1

0

Angular doesn't provide orderBy pipe. See here.

So you have to write it by yourself. Maybe this post can help you: Angular 2. How to apply orderBy?

awmleer
  • 1,658
  • 3
  • 13
  • 28
  • Thank you for your response. I use a library called [angular-pipes](https://github.com/fknop/angular-pipes). so I need not write my custome pipe for this. – just10minutes Jul 09 '17 at 01:50