I am trying to update text through put request.
My HTML where new value to be update is gathered:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="card bg-light mb-3" *ngFor ="let review of webService.review | async">
<div class="card-header">
Review by {{ review.username }}
on {{ review.date | date }}
</div>
<div class="card-body">
{{ review.text }}
<br>
<input [(ngModel)]="text">
</div>
<div class="card-body">
{{ review.stars }} stars
</div>
<div class="card-footer">
<button class="btn btn-primary" routerLink="/reviews" routerLinkActive="active" (click)="onDelete()">Delete</button>
<button class="btn btn-primary" id="editbtn" (click)="onEdit()">Edit</button>
</div>
</div>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
My function that is called when data is submitted
onEdit(){
this.webService.editReview(this.text);
console.log(this.text);
}
My web.service.ts file
editReview(reviewID) {
let postData = new FormData();
postData.append("text", this.text);
return this.http.put(
'http://localhost:5000/api/v1.0/movies/' +
this.movieID + '/reviews/' + this.reviewID, postData
).subscribe(response => {
console.log("Edit - Success");
}
)
}
As said in comments, please do the subscription and success/error handling in the component.
onEdit(){
this.webService.editReview(this.text)
.subscribe(response => {
console.log("Edit - Success");
console.log(this.text);
});
}
//webservice part
editReview(reviewID) {
let postData = new FormData();
postData.append("text", this.text);
return this.http.put(
'http://localhost:5000/api/v1.0/movies/' +
this.movieID + '/reviews/' + this.reviewID, postData
)
}
Observables
need to be subscribed to start processing
onEdit(){
this.webService.editReview(this.text).subscribe(console.log);
console.log(this.text);
}
and in service just return the Observable
editReview(reviewID) {
let postData = new FormData();
postData.append("text", this.text);
return this.http.put(
'http://localhost:5000/api/v1.0/movies/' +
this.movieID + '/reviews/' + this.reviewID, postData
)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.