ngx-http-params
v1.0.4
Published
Make Angular's `HttpParams` instance from simple object. It is similar to `new HttpParams({ fromObject?: {...} })` but use the custom encoder under the hood.
Downloads
32
Readme
NgxHttpParams
Make Angular's HttpParams
instance from simple object.
It is similar to new HttpParams({ fromObject?: {...} })
but use the custom encoder under the hood.
Examples
import { httpParams } from 'ngx-http-params';
httpParams({
num1: 1,
num2: 2
}).toString()
// -> num1=1&num2=2
httpParams({
p1: '1',
p2: 'John'
}).toString()
// -> p1=1&p2=John
httpParams({
d1: new Date(1581061520554 * Math.random()),
d2: new Date(1581061520554 * Math.random())
}).toString()
// -> d1=1994-05-08T04%3A52%3A40.134Z&d2=1971-04-21T02%3A06%3A13.698Z
httpParams({
b1: true,
b2: false
}).toString()
// -> b1=true&b2=false
httpParams({
n1: null,
u1: undefined
}).toString()
// -> n1=
httpParams({
a1: [],
a2: [1, 2, 3]
}).toString()
// -> a2=1&a2=2&a2=3
httpParams({
a: 1,
b: {
x: 2
}
}).toString()
// -> a=1&b.x=2
httpParams({
a: 1,
b: {
x: 2
},
c: {
x: 3,
d: {
y: 5
}
}
}).toString()
// -> a=1&b.x=2&c.x=3&c.d.y=5
httpParams({
'df-fd,x+k': 'a'
}).toString()
// -> df-fd,x+k=a
httpParams({
[1]: 'a'
}).toString()
// -> 1=a
Same here https://stackblitz.com/edit/ngx-http-params