angular - 角常春藤,模板局部变量错误:对象可能为“空”
问题描述
我收到消息错误:“对象可能为‘空’”。在行中modal.customWidth.extra_large
我的代码是:
<app-modal
#modal
[active]="hasCurrentProduct$ | async"
[modalWidth]="modal.customWidth.extra_large">
解决方案
在访问它们的属性之前,您需要检查它modal
并且customWidth
不为空。
更改modal.customWidth.extra_large
为modal?.customWidth?.extra_large
推荐阅读
- mongodb - Mongo中的连接嵌套数组
- amazon-web-services - AWS Lambda 函数会重试多少次以异步调用?
- laravel - rest api 登录资源的最佳实践
- domain-driven-design - 提醒 - DDD
- git - Git 日志获取真正的提交作者
- angularjs - 在按钮中自动添加 ng-hide
- java - RxJava2 - 合并流中的值和副作用
- apache - 将整个子目录设为 410
- c++ - boost 1.72 为 icmp::resolver 获取 icmp::socket io_service
- python - Python:合并 io.BytesIO 形式的音频文件