merge two object arrays with Angular 2 and TypeScript?

前端 未结 6 716
长情又很酷
长情又很酷 2020-12-14 05:19

I have gone across the JavaScript questions on this topic, this question is specifically about Angular2 with TypeScript.

What I am trying to do is to concatenate the

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 05:53

    You can also use the form recommended by ES6:

    data => {
      this.results = [
        ...this.results,
        data.results,
      ];
      this._next = data.next;
    },
    

    This works if you initialize your array first (public results = [];); otherwise replace ...this.results, by ...this.results ? this.results : [],.

    Hope this helps

提交回复
热议问题