Hi guys I'm creating a HTTP request on Angular, but I do not know how to add url arguments (query string) to it.
this.http.get(StaticSettings.BASE_URL).subscribe(
(response) => this.onGetForecastResult(response.json()),
(error) => this.onGetForecastError(error.json()),
() => this.onGetForecastComplete()
);
Now my StaticSettings.BASE_URL is something like a url with no query string like: http://atsomeplace.com/ but I want it to be http://atsomeplace.com/?var1=val1&var2=val2
Where var1, and var2 fit on my Http request object? I want to add them like an object.
{
query: {
var1: val1,
var2: val2
}
}
and then just the Http module do the job to parse it into URL query string.
provided that you have installed jQuery, I do
npm i jquery --save
and include inapps.scripts
inangular-cli.json
You can use Url Parameters from the official documentation.
Example:
this.httpClient.get(this.API, { params: new HttpParams().set('noCover', noCover) })