Angular 4 - HTTP delete not working

后端 未结 2 770
夕颜
夕颜 2021-02-14 16:05

I am trying to create a MEAN crud operation. I have an api in node with the delete http method as so localhost:3000/api/user?id=. Below is t

相关标签:
2条回答
  • 2021-02-14 16:49

    If you are calling this method inside your component, use .subscribe()

    this.userService.deleteUser(user).subscribe(() => console.log("user deleted")); this.errorMessage = error);
    
    0 讨论(0)
  • 2021-02-14 16:50

    You have to subscribe to the call if you want it to execute. See the HttpClient documentation.

    Note the subscribe() method. All Observables returned from HttpClient are cold, which is to say that they are blueprints for making requests. Nothing will happen until you call subscribe(), and every such call will make a separate request. For example, this code sends a POST request with the same data twice:

    Example:

    otherMethod(){
        this.userService.deleteUser(user).subscribe(() => console.log("user deleted"));
    }
    
    0 讨论(0)
提交回复
热议问题