What is the difference between ref-prefix and # in the template reference variable (Angular 2)

I want to understand the difference between the designation of the reference variable variable, as indicated below in the input text fields.

<input type="text" name='name' #name [(ngModel)]='model'>
<input type="text" name='name' ref-name [(ngModel)]='model'>

What is the difference between using #name and ref-name .
Does the scope change when using the name ref? Can anyone suggest best practice and reason?

+4
source share
3 answers

These are two different syntaxes for literally the same thing.

: ( ) "#variable", Angular , "" .

+5

- , DOM. , . .

<input type="text" name='name' #name [(ngModel)]='model'>

#name . #... ref-. # ref- * ngFor. URL: http://www.concretepage.com/angular-2/angular-2-template-reference-variable-example

0

Template reference variable is a variable using which we can access DOM properties.

, DOM. # ref- , , #item ref-item.

:

<input type="text" #name placeholder="Enter your name" />

#name , DOM,

name.placeholder " ", .

name.value "" .

name.type "" .

, .

HTML-

my html page

output

ref-name.

0

Source: https://habr.com/ru/post/1675545/


All Articles