Reputation: 15
I am learning Angular and I have this scenario in one of my services
agree(id: string) {
const headers = new HttpHeaders('Content-Type: application/json');
return this.HttpClient.put(`${this.apiUrl}/agree/`, JSON.stringify(id), {headers});
}
This approach worked without issues as expected...but I realized that to pass the userId is not a Best Practice, instead I use the HttpContext.User to take user Id property on my ASP.Net Core Web API, so I changed my method.
agree() {
return this.HttpClient.put(`${this.apiUrl}/agreeEula/`);
}
Now I have this issue
“Expected 2-3 arguments, but got 1”
I will appreciate any suggestion, Thanks in advance
Upvotes: 1
Views: 1811
Reputation: 2121
This is the signature for HttpClient.put
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<ArrayBuffer>
In case the body in optional, you can pass {} or null as the second argument after the url.
Read more at - https://angular.io/api/common/http/HttpClient#put
Upvotes: 0
Reputation:
You need to put null
or {}
for the 2nd parameter.
agree() {
return this.HttpClient.put(`${this.apiUrl}/agreeEula/`, null);
}
Upvotes: 2