Issue
How to use the $any() type cast function in Angular template?
In angular documentation- https://angular.io/guide/template-typecheck#disabling-type-checking-using-any some description and examples have been given but still, it is not clear.
There one example is given like this-
<p>The item's undeclared best by date is: {{$any(item).bestByDate}}</p>
Solution
Simply wrap a variable with $any()
. No additional code required.
component.ts
export class AppComponent {
val = { name: 'foobar' }
}
component.html
<p>
{{ $any(val).name }}
</p>
stackblitz: https://stackblitz.com/edit/angular-qivjym
Answered By - zmag
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.