角度需要隐藏数组的重复值。有人回答我,它没有显示重复,但是当我使用过滤器更改值时,它显示了旧值以及新值。
.html
<div class="col-md-3">
<div class="form-group">
<label for="">Policy</label>
<select class="form-control" [(ngModel)]="userFilter.policy_id">
<option *ngFor="let policy of policy_id" value="{{policy}}">{{policy}}</option>
</select>
</div>
</div>
.ts
getClaims() {
if (this.userFilter.company_id) {
this.url = 'url.com&company_id=' + this.userFilter.company_id;
this.spinner.show();
} else {
this.url = 'url.com';
this.spinner.show();
}
this.clientData = this.httpClient.get<any>(this.url).subscribe(data => {
console.log(data);
this.spinner.hide();
this.data = data.records;
this.data.forEach(d => this.policy_id.add(d.policy_id));
});
}
答案 0 :(得分:0)
而不是添加到阵列中,请尝试替换它。
getClaims() {
if (this.userFilter.company_id) {
this.url = 'url.com&company_id=' + this.userFilter.company_id;
this.spinner.show();
} else {
this.url = 'url.com';
this.spinner.show();
}
this.clientData = this.httpClient.get<any>(this.url).subscribe(data => {
console.log(data);
this.spinner.hide();
this.data = data.records;
this.policy_id = this.data.map(d => d.policy_id); // this changed
});
}