angular - 错误类型错误:无法读取 null 的属性“替换”(无限循环)
问题描述
问题是当该字段为空时,它处于无限循环中。我无法确定如何修复此错误。这个问题只提供一种特定的服务。
错误:
ItemDetalheComponent.html: 54 ERROR TypeError: Cannot read property 'replace' of null
at ItemDetalheComponent.linkItens (item-detail.component.ts: 60)
at Object.eval [as updateRenderer] (ItemDetalheComponent.html: 54)
at Object.debugUpdateRenderer [as updateRenderer] (core.js: 45294)
at checkAndUpdateView (core.js: 44277)
at callViewAction (core.js: 44637)
at execEmbeddedViewsAction (core.js: 44594)
at checkAndUpdateView (core.js: 44272)
at callViewAction (core.js: 44637)
at execEmbeddedViewsAction (core.js: 44594)
at checkAndUpdateView (core.js: 44272)
这是第 60 行
linkItens(numeroItens: string): string {
const numeroItensTratados = numeroItens.replace(/[^\d]+/g, '');
return `https://teste/#/resultado/${numeros}`;
}
我的想法是从 null 更改为空,也许这将停止带来这个错误。如果有人可以帮助我至少走正确的路,我将不胜感激。
解决方案
numeroItens
如果为空,则使用空字符串
const numeroItensTratados = (numeroItens || '').replace(/[^\d]+/g, '');
推荐阅读
- vba - 如何使位于可滚动 ActiveX 控件文本框中的单词可搜索?
- c# - 某些 1970 年的日期无法从 UTC 正确转换为本地时间
- python-3.x - 如何使用多线程改进我的程序
- json - 如何使用列值在 Spark Scala 中为 withColumn 生成另一个列的名称
- python - 如何使用for循环win32 python在邮件正文中附加多个嵌入图像
- apache-spark - 如何检查火花流中历史/持久数据中已经存在的流数据记录?
- php - 如何修复“未定义的变量:通过”
- python - 在向图中添加另一个元素时遇到问题,例如(填充之间,散点图)到线图已经存在
- ios - iOS13 - 导航栏标题颜色问题
- php - 如何获得一个 PHP-Laravel 宅基地流浪者盒子?