-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
I want to push an array comment in to cabin.comments array and after UPDATE of the cabin array with the new comment in it when the user submits a comment using the onSubmit() and update the cabin with the updateCabin.
In the console when running "ng serve --open" I am getting an error:
error TS1128: Declaration or statement expect
I am using a JSON database in the main folder.
I am really new to angular and I am lost.
This is my component file with my onSubmit
onSubmit(id) {
this.cabin.comments.push(this.comment);
this.cabinService.updatePosts(this.cabin.id);
this.commentForm.reset({
author: '',
rating: 5,
comment: ''
});
}
My cabinService
updatePosts(id){
const data={"cabin": "Cabin"};
return this.http.get<{cabin: Cabin}>('http://localhost:3000/cabins/'+id).pipe(
map(cabin=>{
console.log(cabin);
return{
description: cabin.description,
featured: cabin.featured,
comments: cabin.comments
};
})
).subscribe(updatedEntries=>{
console.log(updatedEntries);
updatedEntries.comments.push(data);
return this.http.put('http://localhost:3000/cabins/' +id, updatedEntries);
console.log(updatedEntries);
});
My JSON database
"cabins": [
{
"id": 0,
"description": "Tucked away on the hillside among lush gardens of banana & citrus trees",
"featured": "true",
"comments": [
{
"rating": 5,
"comment": "Beautiful place!",
"author": "John Gomez",
"date": "2018-10-16T17:57:28.556094Z"
},
{
"rating": 4,
"comment": "Amazing!",
"author": "Paul Villar",
"date": "2017-09-05T17:57:28.556094Z"
}
]
}
]
Metadata
Metadata
Assignees
Labels
No labels