【问题标题】:no http request to server ANGULAR没有对服务器 ANGULAR 的 http 请求
【发布时间】:2018-08-12 21:45:59
【问题描述】:

大家好,这里是我的likePost函数

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)

这是我的 post.html

<button mat-button (click)="likePost(post)">LIKE</button>

但是当我在 Angular 应用程序中单击我的喜欢按钮时,我看不到任何类型的 Angular 对我的服务器的请求 当我在 myserver 中检查它时,什么都没有改变

顺便说一句,一旦触发,该链接将在 myserver 中由该用户创建一个类似,因为该角度应该只浏览一次,类似将被添加

【问题讨论】:

标签: angular http post


【解决方案1】:

你需要在 observable 上调用 subscribe

this.http.post(this.likeurl+post.id+'/like',requestOptions).subscribe((response)=>{
    console.log(response);
});

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多