angular - 错误类型错误:无法读取未定义 core.js:5967 的属性“toLocaleLowerCase”
问题描述
组件.ts
branches: any = [];
branchName: string; // any
ngOnInit(): void {
// this.refreshBranchList();
this.service.getBranchList().subscribe((response: any) => {
this.branches = response;
});
}
Search() {
if (this.branchName !== "") {
this.branches = this.branches.filter((res: { branchName: string; }) => {
return res.branchName.toLocaleLowerCase().match(this.branchName.toLocaleLowerCase());
})
} else if (this.branchName == "") {
this.ngOnInit();
}
}
组件.html
<div class="d-flex float-right">
<input type="text" class="form-control" placeholder="Search here" [(ngModel)]="branchName" (ngModelChange)="Search()">
</div>
它正在按预期搜索值。但是控制台中有一个我不熟悉的错误。有什么我想念的请告诉我。
解决方案
尝试改变这一点
return res.branchName.toLocaleLowerCase().match(this.branchName.toLocaleLowerCase());
对此
return res.branchName?.toLocaleLowerCase().match(this.branchName?.toLocaleLowerCase());
推荐阅读
- sql - Oracle SQl Developer ORA-01017:用户名/密码无效;登录被拒绝
- c++ - 为什么编译器会测试地址中的最低有效位?
- ios - 我可以在没有服务器的情况下从 ios 向 ios 发送推送通知吗?
- sas - 在宏函数中分配 tranwrd 的宏变量输出
- ios - UICollectionViewCell 如果 isSelected 为真,则执行语句,而它从不为真
- android - 圆形背景android UI中的图标图像
- django - django目录结构“django方式”?(/root/project/app 或 /root/project & root/app)?
- angular6 - 无法测试在 Jasmine 中使用 Observable 的方法
- python - 使用 tf.image.rgb_to_grayscale 自定义 preprocessing_function - ValueError:使用序列设置数组元素
- reactjs - 无法读取 'httpOnly: false' Cookie