Skip to content

Commit

Permalink
fix(common): allow number or boolean as http params (#40663)
Browse files Browse the repository at this point in the history
This change fixes an incompatibility between the old `@angular/http` package
and its successor (`@angular/common/http`) by re-introducing the types that were supported before.

It now allows to use number and boolean directly as HTTP params, instead of having to convert it to string first.

Before:

    this.http.get('/api/config', { params: { page: `${page}` } });

After:

    this.http.get('/api/config', { params: { page }});

`HttpParams` has also been updated to have most of its methods accept number or boolean values.

Fixes #23856

BREAKING CHANGE:

The methods of the `HttpParams` class now accept `string | number | boolean`
instead of `string` for the value of a parameter.
If you extended this class in your application,
you'll have to update the signatures of your methods to reflect these changes.

PR Close #40663
  • Loading branch information
cexbrayat authored and zarend committed Feb 26, 2021
1 parent 383d226 commit 91cdc11
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 272 deletions.
2 changes: 1 addition & 1 deletion aio/content/guide/http.md
Expand Up @@ -72,7 +72,7 @@ The `get()` method takes two arguments; the endpoint URL from which to fetch, an
options: {
headers?: HttpHeaders | {[header: string]: string | string[]},
observe?: 'body' | 'events' | 'response',
params?: HttpParams|{[param: string]: string | string[]},
params?: HttpParams|{[param: string]: string | number | boolean | ReadonlyArray<string | number | boolean>},
reportProgress?: boolean,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
Expand Down

0 comments on commit 91cdc11

Please sign in to comment.