angular - 什么?意思是 Angular 5?

标签 angular

<分区>

我知道我是否有类似 product.id == 1 的东西?东西:不是东西。这意味着如果 id = 1,则选择“stuff”。如果不是,则选择“不是东西”。以下是什么意思:

product?.id.name

最佳答案

? 表示安全 navigation operator

来自文档

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.

这具体意味着,如果您绑定(bind)到 View 的值是空值,那么它应该返回空值,否则返回实际值,这样您在呈现模板时就不会遇到任何问题。

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

product?.id.name

它检查生产对象是否存在,然后检查是否有 id。 因为你没有 ? 在 id 之后。 它会抛出一个错误“无法读取‘name’未定义的属性”。

关于angular - 什么?意思是 Angular 5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51615237/

相关文章:

google-app-engine - 将基本的 Angular 2 应用程序部署到 Google App Engine

javascript - Angular 4 Http POST 不工作

angular - 使用angular ngrx store效果按id查询数据

javascript - 在 ngAfterViewInit 中检索由 ngFor 创建的元素

javascript - 在过滤器管道上使用多个字段| Angular 4

Angular5 未设置 X-XSRF-TOKEN header

angular - 错误 : Unexpected value 'Http' imported by the module 'AppModule' at SyntaxError. ZoneAwareError

javascript - Angular 2 - 带有路由器 socket 的测试组件

javascript - 如何将逗号分隔的 JSON 值显示为列表?

javascript - 断言一个组件只能用作另一个组件的子组件