Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat is not a function

Hello guys I'm trying to put the all comments in array to show at *ngFor but at subscribe data comes json object so it cannot be concat.

here is my code

TS

this.http.post('http://' + this.ipAdress + ':3100/api/infitineComments/:id', { "page": this.page }) 
    .map(res => res.json())
    .subscribe(data => {


      if (...) { //error part
      }

      else {

        let d = [];
        for(let i = 0; i< data.length; i++){
          d.push(data[i])
        }//I did this part because data was  object in array type , also 
         //doesnt work

        this.comments = this.comments.concat(d);

        console.log("data: ", this.comments);
      }
    }, err => {
      console.log("err: ", err);
    });

Here small picture of my error, all list covers id, comment, userId... enter image description here

Thank you

like image 844
erdemgunenc Avatar asked Sep 09 '26 00:09

erdemgunenc


1 Answers

Check that this.comments is well initialized as an array.

this.comments = []
like image 89
Martin Choraine Avatar answered Sep 11 '26 17:09

Martin Choraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!