angular - ERROR 错误:尝试区分“假”时出错。只允许使用数组和可迭代对象
问题描述
我在 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
为空时出现此错误。
拜托,你能问我任何想法,我怎样才能修改代码以不显示此错误?这对我来说非常重要。
解决方案
推荐阅读
- c# - 如何在 C# 中发送 XML 文件?
- qt - 将 QML 属性链接到 QSerial 输出
- php - PHP (ImageMagick) - 从源数据合并图像
- apache - .htaccess/virtualhost 动态阻止列表 + 错误文档
- rust - 为什么 get 方法没有在 reqwest 中返回 Response 对象?
- javascript - 如何从具有负值的拆分字符串中获取数组
- google-chrome - chrome 87:请求的资源上不存在“Access-Control-Allow-Origin”标头
- python - 如何最好地使用云功能处理来自谷歌长期运行操作的异步响应
- javascript - 如何使用具有不同背景颜色的每个表格行
- python - 作为类属性的函数