javascript - chaining methods inside *ngIf
问题描述
project[col.field][selectedUserRole.value].join(',').length
If I use the above line of code inside *ngIf or inside curly braces {{}}, I am getting
ERROR TypeError: Cannot read property 'join' of undefined
error
解决方案
像这样使用安全导航运算符(?)
-
project[col?.field][selectedUserRole?.value]?.join(',')?.length
?
或安全导航运算符在模板内绑定时检查 Null、false、未定义值。
推荐阅读
- julia - 如何围绕字符串数组创建一个薄包装器C
- ios - Branch.io:为应用索引生成批量内容参考
- ffmpeg - 如何在 JPEG 中编码 HEVC 平铺?
- php - 如何通过一个提交按钮单击执行两个表单操作?
- c# - C# 从文件中加载表单
- javascript - 在 Dropzone JS 中将图像克隆为缩略图
- html - 最后两个 div 干扰:文本消失在前一个 div 的部分之后
- android - 如何将片段中的 ListView 对象的数据传递给 Activity?
- java - Elasticsearch 错误 - 尝试搜索附件中的内容时
- amazon-web-services - 私有云(SaaS 提供商)基础架构与内部基础架构有何不同?