角隐藏数组的重复值

时间:2019-05-07 08:06:11

标签: angular

角度需要隐藏数组的重复值。有人回答我,它没有显示重复,但是当我使用过滤器更改值时,它显示了旧值以及新值。

.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));
  });
}

还要附加图像。一页显示2个值。当我即时过滤数据。其显示2个先前值和1个新值。我只想要新值。 enter image description here enter image description here

enter image description here

1 个答案:

答案 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
  });
}