我会尽力解释我的情景。我有一个搜索过滤器,当在Angular 4中使用以下格式时可以工作:
<select [(ngModel)]="city_filter" (change)="applyFilter('city',$event.target.value)">
<option value="Ahmedabad">Ahmedabad</option>
<option value="Bangalore">Bangalore</option>
<option value="Bengaluru">Bengaluru</option>
<option value="Delhi">Delhi</option>
<option value="Dilli">Dilli</option>
</select>
尝试方法时停止工作:
<select [(ngModel)]="city_filter" (change)="applyFilter('city',$event.target.value)">
<option value="Ahmedabad">Ahmedabad</option>
<option value="Bangalore/Bengaluru">Bangalore/Bengaluru</option>
<option value="Delhi/Dilli">Delhi/Dilli</option>
</select>
如何使这项工作成功,以便过滤器适用于班加罗尔/班加罗尔?
在applyFilter
中,这是函数:
applyFilter (key: string, value) {
this.filter.set(key, value);
if (value === 'null') {
this.filter.delete(key);
}
let p = new HttpParams();
this.filter.forEach((v, k) => {
p = p.append(k, v);
});
this.loading = true;
this.jobService.searchJob(p).subscribe(res => {
this.loading = false;
this.valueStack = res;
this.jobs = res.jobs || [];
}, err => {
this.loading = false;
this.jobs = [];
});
}
答案 0 :(得分:1)
而不是这个
<option value="Bangalore/Bengaluru">Bangalore/Bengaluru</option>
试试这个
<option [ngValue]="'Bangalore' || 'Bengaluru'">Bangalore/Bengaluru</option>