Concat 不是函数

erd*_*enc 2 concat angular

大家好,我正在尝试将所有评论放在数组中以在 *ngFor 上显示,但在订阅数据时出现 json 对象,因此无法连接。

这是我的代码

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);
    });
Run Code Online (Sandbox Code Playgroud)

这是我的错误的小图片,所有列表都包括 id、comment、userId... 在此处输入图片说明

谢谢

Mar*_*ine 5

检查是否this.comments已初始化为数组。

this.comments = []
Run Code Online (Sandbox Code Playgroud)