[Angular] The $any() type cast function

2021/4/19 18:58:30

本文主要是介绍[Angular] The $any() type cast function,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Sometimes a binding expression triggers a type error during AOT compilation and it is not possible or difficult to fully specify the type. To silence the error, you can use the $any() cast function to cast the expression to the anytype as in the following example:

<p>The item's undeclared best by date is: {{$any(item).bestByDate}}</p>

Using $any() prevents TypeScript from reporting that bestByDate is not a member of the item object.

The $any() cast function also works with this to allow access to undeclared members of the component.

<p>The item's undeclared best by date is: {{$any(this).bestByDate}}</p>

The $any() cast function works anywhere in a binding expression where a method call is valid.



这篇关于[Angular] The $any() type cast function的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程