Daniel Vágner
Daniel Vágner

Reputation: 846

Get params Angular

I have problem with params. I am using filter method to get every key, value from different componet (form).

The problem is with result in the end.

 filterTable(filters: { data: any; isReset: boolean }) {
    let params = new HttpParams();

    for (const key in filters.data) {
      if (Object.prototype.hasOwnProperty.call(filters.data, key)) {
        const jsonData = JSON.stringify({ drilldown: { [key]: { op: 'EQ', value: filters.data[key] } } });
        params = params.append('filter', jsonData);
      }
    }

enter image description here

Is there way how could i not add in query params key with null value?

Upvotes: 1

Views: 58

Answers (1)

lovis91
lovis91

Reputation: 2171

If you want to remove the entire filter, just add this condition to your if : filters.data[key]

for (const key in filters.data) {
    if (Object.prototype.hasOwnProperty.call(filters.data, key) && filters.data[key]) {
        const jsonData = JSON.stringify({ drilldown: { [key]: { op: 'EQ', value: filters.data[key] } } });
        params = params.append('filter', jsonData);
    }
}

Upvotes: 3

Related Questions