大家好,这是我的喜欢帖子函数
likePost(post){
let head = new Headers({ 'Content-Type': 'application/json',
"Authorization":"JWT "+localStorage.getItem("token")
});
let requestOptions = new RequestOptions({headers: head});
// this.http.post(this.likeurl,requestOptions)
this.http.post(this.likeurl+post.id+'/like',requestOptions)
这是我的帖子.html
<button mat-button (click)="likePost(post)">LIKE</button>
但是当我在 Angular 应用程序中单击我的"喜欢"按钮时,我看不到 Angular 对我的服务器的任何类型的请求 当我在MyServer中检查它时,没有任何变化
顺便说一句,一旦触发链接,该用户将在myserver中为该角度创建一个喜欢,只需浏览一次,就会添加类似内容
你需要在可观察量上调用subscribe
,
this.http.post(this.likeurl+post.id+'/like',requestOptions).subscribe((response)=>{
console.log(response);
});