微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[Angular] The non-null assertion operator ( ! )

When you use TypeScript's --strictnullchecks flag, you can prevent the type checker from throwing an error with Angular's non-null assertion operator, !.

The Angular non-null assertion operator causes the TypeScript type checker to suspend strict null and undefined checks for a specific property expression.

For example, you can assert that item properties are also defined.

<!-- Assert color is defined, even if according to the `Item` type it Could be undefined. -->
<p>The item's color is: {{item.color!.toupperCase()}}</p>

Often, you want to make sure that any property bindings aren't null or undefined. However, there are situations in which such states are acceptable. For those situations, you can use Angular's non-null assertion operator to prevent TypeScript from reporting that a property is null or undefined.

The non-null assertion operator, !, is optional unless you turn on strict null checks.

For more information, see TypeScript's strict null checking.

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐