加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

什么?意味着角度5?

发布时间:2020-12-17 07:36:04 所属栏目:安全 来源:网络整理
导读:参见英文答案 Why we use “?” operator in template binding in angular 22个 我知道如果我有像product.id == 1这样的东西?东西:不是东西.这意味着如果id = 1,则选择“stuff”.如果没有,那么选择“不是东西”.以下是什么意思: product?.id.name ?手段
参见英文答案 > Why we use “?” operator in template binding in angular 22个
我知道如果我有像product.id == 1这样的东西?东西:不是东西.这意味着如果id = 1,则选择“stuff”.如果没有,那么选择“不是东西”.以下是什么意思:
product?.id.name
?手段安全 navigation operator

来自Docs

The Angular safe navigation operator (?.) is a fluent and convenient
way to guard against null and undefined values in property paths. Here
it is,protecting against a view render failure if the currentHero is
null.

这特别意味着如果绑定到视图的值为null,则它应返回null,否则返回实际值,这样在呈现模板时不会出现任何问题.

在您提供的上述示例代码中,

产品?.id.name

它检查生成对象是否存在,然后检查是否有id.既然你没有?在id之后.它将抛出一个错误“无法读取’name’未定义的属性”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读