Reputation: 741
In my program i want to pass get with parameters. One of those parameters are null. But when i set this property to URLSearchParams it doesnt appers in final Url? Is this possible?
Here the object with parameters which i pass as parameters:
{zpm_id:112, tow_id:null}
And here part of my function:
public getDaneOkna(rodzaj: string, symbolOkna: string, parametry: any) {
let params = new URLSearchParams();
Myheaders = new Headers();
for (var key in parametry) {
params.set(key, parametry[key]);
}
return this._http.get(this.adresSerwera + '/dane/' + symbolOkna,
{
headers: Myheaders,
search: params
}
)
Upvotes: 0
Views: 6068
Reputation: 3062
Its generally suggested to avoid using null completely in typescript. Use 'undefined' instead.
https://basarat.gitbooks.io/typescript/docs/tips/null.html
But if for some reason you ended up passing parametry as undefined, you won't be able to access any properties of it, so this
parametry[key]
would generate an error, whereas this
console.log(parametry)
Wouldn't generate an error, it would just print 'undefined'
Other commenters are right its best to avoid passing in an undefined parameter. If you must, checks inside the method for its existence would be wise...
Upvotes: 0