[英]Angular PUT request - URL not found
我正在尝试通过放置请求更新文本。
我的 HTML 收集了要更新的新值:
<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 -->
我提交数据时调用的函数
onEdit(){
this.webService.editReview(this.text);
console.log(this.text);
}
我的 web.service.ts 文件
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");
}
)
}
如评论中所述,请在组件中进行订阅和成功/错误处理。
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
才能开始处理
onEdit(){
this.webService.editReview(this.text).subscribe(console.log);
console.log(this.text);
}
在服务中只返回 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
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.