diff --git a/aio/content/examples/template-syntax/src/app/app.component.html b/aio/content/examples/template-syntax/src/app/app.component.html index 8627c73bcb..fc5b36d35a 100644 --- a/aio/content/examples/template-syntax/src/app/app.component.html +++ b/aio/content/examples/template-syntax/src/app/app.component.html @@ -821,6 +821,29 @@ The null hero's name is {{nullHero && nullHero.name}} top + +

$any type cast function $any( ).

+ +
+ + +
+ The hero's marker is {{$any(hero).marker}} +
+ +
+ +
+ + +
+ Undeclared members is {{$any(this).member}} +
+ +
+ +top +

Enums in binding

diff --git a/aio/content/guide/template-syntax.md b/aio/content/guide/template-syntax.md index 31741ccb4d..fd0f37d184 100644 --- a/aio/content/guide/template-syntax.md +++ b/aio/content/guide/template-syntax.md @@ -1983,6 +1983,29 @@ You'll need this template operator when you turn on strict null checks. It's opt
+{@a any-type-cast-function} + +## The `$any` type cast function (`$any( )`) + +Sometimes a binding expression will be reported as a type error 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](http://www.typescriptlang.org/docs/handbook/basic-types.html#any). + + + + +In this example, when the Angular compiler turns your template into TypeScript code, +it prevents TypeScript from reporting that `marker` is not a member of the `Hero` +interface. + +The `$any` cast function can be used in conjunction with `this` to allow access to undeclared members of +the component. + + + + +The `$any` cast function can be used anywhere in a binding expression where a method call is valid. + ## Summary You've completed this survey of template syntax. Now it's time to put that knowledge to work on your own components and directives.