Cannot find name 'HttpParamsOptions'. Angular 6

Viewed 3462

maybe somebody know why Angular doesn't understand the the HttpParamsOptions, or maybe there are another way for adding a request a header and params.

`public getJobs(options: {page?: number, size?: number} = {}, database: string): Observable <IJobs[]> {
  const headers = new HttpHeaders().set('Dataset-Id', database);
  const params: any = {
       page: options.page || 0,
       size: options.size || 10
     };
 const httpParams: HttpParamsOptions = { fromObject: params } as HttpParamsOptions;
 const headerwithParams = { params: new HttpParams(httpParams), headers: headers };
   return this.http.get<IJobs[]>('/api/jobs', headerwithParams);
}`
2 Answers

The Angular Docs say that the HttpParams constructor can take an HttpParamsOptions object as its only parameter.

But the Angular team forgot to create any documentation for this class.

There is a lot of missing documentation in Angular.

If you are interested in passing the http params, use HttpParams

For the HttpClient get request there are multiple overloaded get methods. see this HttpClient

For just passing the headers, see below.

const headers = {};
headers['Accept'] = 'application/json';
headers['Content-Type'] = 'application/json';
this.httpHeaders = new HttpHeaders(headers);
return this.http.get<IJobs[]>(url_here, {headers: this.httpHeaders })
Related