import { Injectable } from '@angular/core';
import {HttpClient, HttpParams} from "@angular/common/http";
export interface Filter {
countryCode?: string,
postalCode?: string
}
@Injectable({
providedIn: 'root'
})
export class CountriesService{
constructor(private http: HttpClient) { }
getCountries(filters: Filter) {
const params = new HttpParams();
if (filters.countryCode) params.append('countryCode', filters.countryCode);
if (filters.postalCode) params.append('postalCode', filters.postalCode);
return this.http.get('/api/countries', {params: params})
}
}
I have an Angular 7 http service that fetches cities from an end point, I want to pass optional multiple query params to filter the results on the server side but it doesnt work however it works with just one param. These params are being ignored or not passed to the request.