错误错误:尝试区分'false'时出错。仅允许数组和可迭代

时间:2018-09-20 13:37:29

标签: angular typescript

我在TS中具有此功能:

getClientContact(clientid: string) {
        if (this.client&& this.client.length > 0) {
        const [filteredClientId] = this.client.filter(pt => pt.client_id === clientid);
        if (typeof filteredClientId !== 'undefined' && clientid === filteredClientId.client_id) {
        return filteredClientId.contactNo;
    }
  }
}
getClientAdd(clientid: string) {
        if (this.client&& this.client.length > 0) {
        const [filteredClientadd] = this.client.filter(pt => pt.client_id === clientid);
        if (typeof filteredClientadd !== 'undefined' && clientid === filteredClientadd.client_id) {
        return filteredClientadd.address;
    }
  }
}

onSelect(clientid) {
            this.selectedClient = null;
            for (let i = 0; i < this.client.length; i++) {
                if (this.client[i].client_id === clientid) {
                    this.selectedClient = this.client[i];
                }

            }
        }

我像这样的代码用html来称呼它:

  <fieldset>
      <legend>Client Data</legend>
      <div class="input-field col s12">
        <select (change)="onSelect($event.target.value)" [(ngModel)]="selectedClient.client_id" formControlName="client_id" id="client_id"
          materialize="material_select" [materializeSelectOptions]="client">
          <option value="" disabled selected>Nome:</option>
          <option *ngFor="let item of client" [value]="item.client_id">{{item.clientName}}</option>
        </select>
      </div>
      <br>
      <div class="input-field col s12">
       Phone:
        <br>
        <span>{{getClientContact(selectedClient.client_id)}}</span>
        <br>
      </div>
      <br>
      <div class="input-field col s12">
        Address:
        <br>
        <span>{{getClientAdd(selectedClient.client_id)}}</span>
        <br>
      </div>
    </fieldset>

在这段代码中,当ERROR Error: Error trying to diff 'false'. Only arrays and iterables are allowed为空时,出现此错误client

请,您能问我任何想法吗,如何修改代码以不显示此错误?对我来说很重要。

0 个答案:

没有答案