I have 3 ngModel in my UI which are binded in my angular application. All of them are selected by user using multi select dropdown.
country = ["India", "US"]
state = ["Delhi", "MP","UP"]
city = ["gzb","xyz"]
I have a custom filter where i have to filter data based on these responses
filter = {
country: this.country,
state: this.state,
city: this.city
}
result = data.filter(e =>
Object.entries(filters).every(([key,vals])=>vals.includes(e[key])))
There is a scenario where only country array is there and other 2 are empty. Here my filter will fail. How to check null
Test Data
data=[{
"name":"hello",
"gender":"male",
"country":"India",
"state":"Delhi",
"city":"gzb"
}]
data?vals.length === 0 || vals.includes(...). The snippet is updated. What doesn't work in that?