Angular 2 - Sort list from Observable

前端 未结 1 663
借酒劲吻你
借酒劲吻你 2021-02-05 04:49

What is the best way to sort a list of items coming from an Observable and still be able to use the async pipe? (I read that making a cust

1条回答
  •  既然无缘
    2021-02-05 05:43

    If you call .subscribe() you get a Subscription, the async pipe expects an Observable.

    If you change it to

    this.test$ = Observable.of(['one', 'two', 'three'])
    .map((data) => {
        data.sort((a, b) => {
            return a < b ? -1 : 1;
         });
        return data;
     });
    

    you can use the async pipe with test$

    0 讨论(0)
提交回复
热议问题