Reputation: 997
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...
Thank you
Upvotes: 3
Views: 27560
Reputation: 13
Since from the screenshot there are an _id
, I believe your're currently working with database.
To update the database, you should use any method specific to what database you're working on. Example: couchdb, puchdb, etc.
Upvotes: 0
Reputation: 2431
Check that this.comments
is well initialized as an array.
this.comments = []
Upvotes: 6