0

I have Java service which retrieves table from oracle database and I want to display the result in Angular application, also I have an array of Objects in Angular:

resultSet:Info[]=[];

service:

 pastHourInfo() {
        const url='/SearchApp-1.0/users/transaction';
        return this.http.get(url).pipe(map((data:any)=>data));
    }

this is my service subscribtion:

checkPasHourInfo() {
        this.searchService.pastHourInfo().subscribe(data => {
            console.log("we got: ",data);
            this.resultSet.push(data);
            console.log(this.resultSet.length);
        },
        error => {
          console.log("Error",error);

    },);

Problem is the next. The result is 77 rows . console.log("we got: ",data) gives correct result. you cans see it here

but console.log(this.resultSet.length); prints "1" when it must be 77.

What is the problem?

2
  • Are you trying to push array into an array? Commented Nov 21, 2018 at 8:32
  • You are pushing array inside array. Just replace it like this :this.resultSet = data; instead of this.resultSet.push(data); Commented Nov 21, 2018 at 8:55

3 Answers 3

1

From your screenshot it seems that your are pushing the array into your result array, you could spread your data into the array as such:

this.resultSet.push(...data);
Sign up to request clarification or add additional context in comments.

Comments

1

You are pushing an array into an array. So your array looks like this

resultSet[].length = 1;
resultSet[0].length = 77;

Instead of doing:

this.resultSet.push(data);

try this:

this.resultSet.concat(data);

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

Comments

0

You can add array into another array as below:

this.resultSet.concat(data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.