首页 > 其他 > 详细

[Angular 9] Built-in template syntax $any

时间:2020-02-17 17:48:45      阅读:101      评论:0      收藏:0      [点我收藏+]

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 any type as in the following example:

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

When the Angular compiler turns this template into TypeScript code, it prevents TypeScript from reporting that bestByDate is not a member of the item object when it runs type checking on the template.

The $any() cast function also works with this to allow access to undeclared members of the component. The $any() cast function works anywhere in a binding expression where a method call is valid.

 

[Angular 9] Built-in template syntax $any

原文:https://www.cnblogs.com/Answer1215/p/12322685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!