Reputation: 197
I'm trying to add a filter to a dropdown
<select class="form-control" [ngModel]="value" (ngModelChange)="onChange($event)">
<option selected value="0">{{ first_value }}</option>
<option *ngFor="let i of data" [value]="i.id">
{{i.city_name}}
</option>
</select>
How can I add a filter like *ngIf="city_country == 'US'"
?
Upvotes: 0
Views: 1872
Reputation: 744
As we are using structural directive we couldn't use two on same tag.
so either you can use new variable to get all the city's within US or we can have a get function to get all the city's with in US
// inside component class
get citiesWithinUS() {
return this.data.filter(x => x.city_country === 'US')
}
// inside html page
<select class="form-control" [ngModel]="value" (ngModelChange)="onChange($event)">
<option selected value="0">{{ first_value }}</option>
<option *ngFor="let i of citiesWithinUS" [value]="i.id">
{{i.city_name}}
</option>
</select>
Upvotes: 1