What Is a Template Reference Variable?
A template reference variable is a reference to a DOM element or directive within a template. Using template reference variable we access the values of DOM element properties.Template reference variable is declared using # and ref- as prefix, for example #myVar and ref-myVar and
NgForm
directive step by step using TypeScript.Template Reference Variable Syntax
We can use template reference variable by two ways.
1. Using #
Find the example.
2. Using ref-
Find the example.
Template Reference Variable using Input Text Box
Here we will discuss template reference variable using input text box. Template reference variable is a variable using which we can access DOM properties. In our example we are using following DOM properties of input box.1. placeholder
2. type
3. value Now find the code snippet.
mobile.placeholder : It will give placeholder of our text box if we have specified.
mobile.value : It will give value of our text box.
mobile.type : It will give type of input element. In our example type is text.
Template Reference Variable using Select Box
Here we will discuss template reference variable with select box.Template Reference Variable with NgForm
Now we will discuss how to accessNgForm
directive using template reference variable. We are creating a sample form here.ngSubmit : It enables binding angular expressions to
onsubmit
event of the form. Here on form submit onSubmitPersonForm
component method will be called. ngForm : It is the nestable alias of form directive
0 comments:
Post a Comment