[Angular] The non-null assertion operator ( ! )
2021/4/19 18:58:38
本文主要是介绍[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.
这篇关于[Angular] The non-null assertion operator ( ! )的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-04百万架构师第六课:设计模式:策略模式及模板模式
- 2025-01-04百万架构师第七课:设计模式:装饰器模式及观察者模式
- 2025-01-04适用于企业管理的协作工具API推荐
- 2025-01-04挑战16:被限流的CPU
- 2025-01-03企业在选择工具时,如何评估其背后的技术团队
- 2025-01-03Angular中打造动态多彩标签组件的方法
- 2025-01-03Flask过时了吗?FastAPI才是未来?
- 2025-01-0311个每位开发者都应知道的免费实用网站
- 2025-01-03从REST到GraphQL:为什么以及我是如何完成转型的
- 2025-01-03掌握RAG:从单次问答到连续对话