I want to send query parameters within a GET request. My class looks like this:
@Injectable()
export class Loader implements TranslateLoader{
constructor(private http: Http){
}
getTranslation(lang: string): Observable<any>
{
return this.http.get(routes.Localization.Get) ;// in that place I need to pass params
}
}
How can I do this?
You can leverage the URLSearchParams
class for this:
getTranslation(lang: string): Observable<any> {
let params = new URLSearchParams();
params.set('param1', 'value1');
return this.http.get(routes.Localization.Get, { search: params });
}
This will result to an URL like this (parameters are added in the query string): http://...?param1=value1
.
See the documentation of this class:
It now providers support for encoding / decoding parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With