Reputation: 1407
issue here with the delete request (in angular 4), as i get a
requestheaders does not exist in the type requestoptionargs
below is my code:
myMethod(id: string, reason: string): Observable<any> {
const reqHeaders = new Headers({
'Content-Type': 'application/json'
});
const body =
`{"reqId": "${id}",
"reqReason": "${reason}"
}`;
return this.httpClient.delete(
`http://localhost:188/.../1677777555`,
new RequestOptions({ reqHeaders, body }))
.map(rez => JSON.parse(rez))
// .catch(error => this.handleError(error))
;
}
on this line is where i get the error new RequestOptions({ requestHeaders, body }))
Any obvious faults here?
Edit: another variant
Same body as before and:
const options = new RequestOptionsArgs({
body: body,
method: RequestMethod.Delete
});
return this.httpClient.request('http://testAPI:3000/stuff', options);
}
now I get a:
RequestOptionsArgs refers to a type but is beingused as a value here
Upvotes: 1
Views: 2680
Reputation: 176956
as per documentation try like this : https://angular.io/api/common/http/HttpClient#members
can you tryout general request like this
let options = new RequestOptionsArgs({
body: body,
method: RequestMethod.Delete
headers : reqHeaders
});
this.http.request('http://testAPI:3000/stuff', options)
.subscribe((ok)=>{console.log(ok)});
Upvotes: 3
Reputation: 1339
Try this one:
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
myMethod(id: string, reason: string {
let params = new HttpParams()
.append('id', id)
.append('reason', reason)
let headers = new HttpHeaders({ 'Content-Type': 'application/JSON' });
return this.httpClient.delete<any>('http://localhost:188/.../1677777555', { headers: headers, params: params })
.map(rez => JSON.parse(rez));;
Upvotes: 3