Template reference variables

Pass value to an event handler

See console for output.


Template reference variable with disabled button

btn refers to the button element.


Reference variables, forms, and NgForm

{{ submitMessage }}

JSON: {{ itemForm.form.value | json }}


Template Reference Variable Scope

This section demonstrates in which situations you can access local template reference variables (#ref).

Accessing in a child template

Value: {{ ref1.value }}

Here's the desugared syntax:

Accessing from outside parent template. (Doesn't work.)

Here's the desugared syntax:

*ngFor and template reference variable scope

Accessing a on an ng-template

See the console output to see that when you declare the variable on an ng-template, the variable refers to a TemplateRef instance, which represents the template.