HiveBrain v1.2.0
Get Started
← Back to all entries
patterntypescriptangularMajor

merge two object arrays with Angular 2 and TypeScript?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
angulartypescriptwithobjectarraysandmergetwo

Problem

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 json objects to an array.

My code looks something like this,

public results: [];

public getResults(){
    this._service.get_search_results(this._slug, this._next).subscribe(
            data => {
                this.results.concat(data.results);
                this._next = data.next;
            },
            err => {
                console.log(err);
            }
        );
}


How can I concatenate data.results to this.results with typescript and angular?

this._slug and this._next are set on class.

thanks.

Solution

With angular 6 spread operator and concat not work. You can resolve it easy:

result.push(...data);

Code Snippets

result.push(...data);

Context

Stack Overflow Q#38092458, score: 80

Revisions (0)

No revisions yet.