Java教程

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

本文主要是介绍[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 ( ! )的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!