Angular service An argument for 'model' was not provided

Issue

I have a service and it accepts id as paramter and I am requesting the route with the id but I received the error above on my service . Any idea?

enter image description here

#service

const apiBaseUrl = `${environment.apiUrl}/api/userprofile`;


    deactivateUserProfileStatus(id: number) {
        return this.httpRequestService.put(`${apiBaseUrl}/inactive/${id}`);
      }

#ts

DeactivateUserProfileStatus(id: number) {
    this.isInProgress = true;
    this._userService
      .deactivateUserProfileStatus(id)
      .pipe(
        finalize(() => {
          this.isInProgress = false;
        })
      )
      .subscribe({
        next: (res) => {
          this._notificationService.showSuccess(
            'User status has been updated successfully.'
          );
          // this.generalForm.disable();
          this.getUserGeneralDetails();
          // this._router.navigate(['transactions']);
        },
        error: (err) => {
          this._notificationService.showError(
            'Something went wrong, Try again later.'
          );
          this.isInProgress = false;
        },
        complete: () => {
          this.isInProgress = false;
        },
      });
  }
}

Solution

You should add the body (or atleast empty body) for your PUT request.

(method) HttpClient.put(url: string, body: any, options: {
    headers?: HttpHeaders | {
        [header: string]: string | string[];
    };
    observe?: "body";
    params?: HttpParams | {
        [param: string]: string | string[];
    };
    reportProgress?: boolean;
    responseType: "arraybuffer";
    withCredentials?: boolean; 
}): Observable<...> (+14 overloads)

the only GET requests call without body just by URL.

Answered By – Arash Etemad

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published