如何在 Angular 12 中提出补丁请求?

How can I make Patch request in Angular 12?

如何使用补丁请求发送 JSON 数据以及连接到 API 的方法?

private baseUrlRemoveNotifications: string =
   "api/v1.0/UploadDownload/removeNotifications";  
public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
   let username = onlineUserModel.userName;
   const url = `${this.baseUrlRemoveNotifications}`;
   const options = {
     headers: new HttpHeaders({
       "Content-Type": "application/json",
     }),
   };
   return this.http.patch(
     `${this.baseUrlRemoveNotifications}`,
     username,
     options
   );
 }

你可以试试这段代码:

public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
    let targetUsername = onlineUserModel.userName;
    const url =
      this.baseUrlRemoveNotifications +
      "/" +
      this.cookieService.get("username") +
      "/" +
      targetUsername;
    const body = {};
    const options = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": this.cookieService.get("XSRF-TOKEN"),
      }),
    };
    this.http.patch<any>(url, body, options).subscribe((data) => {
      console.log("hi this is put request", data);
    });
  }