[Angular 9] Built-in template syntax $any

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 item‘s 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.

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

时间: 2024-10-16 23:54:08

[Angular 9] Built-in template syntax $any的相关文章

[Angular Directive] Create a Template Storage Service in Angular 2

You need to define a <template> to be able to use it elsewhere in your app as a TemplateRef. You can store these TemplateRefs in a Service and then access them from any @Directive or @Component in your app. We want to create a service and a componen

Template Syntax

1 simple binding @Template({ inline:'<h1>{{myName}}</h1>' }) constructor() { this.myName = 'Jackey'; } 2 local variables and event handler @Template({ inline:'<h1>{{myName}}</h1>' + '<input type="text" #newname/>' +

Angular Directive: link vs compile vs controller

Compile : This is the phase where Angular actually compiles your directive. This compile function is called just once for each references to the given directive. For example, say you are using the ng-repeat directive. ng-repeat will have to look up t

【Angular专题】——(2)【译】Angular中的ForwardRef

原文地址:https://blog.thoughtram.io/angular/2015/09/03/forward-references-in-angular-2.html 作者:Christoph Burgdorf 译者注:文章内容比较老,控制台信息等与新框架不完全一致,理解思路即可. 一. 问题点在哪里 先做一个小声明,我们现在拥有一个AppComponent,并使用DI系统向其中注入了一个NameService,因为我们使用的是Typescript,所以需要做的工作就是在构造函数的参数中

AngularJS是什么

先标明来源: https://code.angularjs.org/1.3.15/docs/guide/introduction 也就是官网针对1.3.15版的说明 What Is Angular? AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML’s syntax to express 

Getting Started with Django Rest Framework and AngularJS

转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReSTful API is becoming a standard component of any modern web application. The Django Rest Framework is powerful framework for developing ReST endpoints

创建自定义指令(二)

一.使用嵌入包含 嵌入包含的意思是将一个文档的一部分通过引用插入到另一个文档中.在指令的上下文信息中,当你要创建一个可以包含任意内容的包装器指令时,这将十分有用. <script type="text/ng-template" id="template"> <div class="panel panel-default"> <div class="panel-heading"> <h4

Beautiful Walls

[1553] Beautiful Walls 时间限制: 1000 ms 内存限制: 65535 K 问题描述 To simplify the building process, XadillaX built some template on the ground. The template is a very big wall and the height of each unit may be different. 8Mao and Hungar have to choose any par

AngularJS 笔记

Module ng-app 可以不必赋值:<div ng-app> 即合法 Module :app 的不同组件--controllers,services,filters,directives 的容器 module 的构造函数有两个参数:第一个字符串是本 module 的名字,第二个参数是其依赖的其他 module 一个 html 文档只有第一个 ng-app 能自动载入(auto-bootstrap),其他 app 要手动 angular.bootstrap,ng-app 不可嵌套.一般可以