模板引用变量(Angular 2)中的 ref- 前缀和 # 之间有什么区别 [英] What's the difference between ref- prefix and # in Template reference variable (Angular 2)
问题描述
我想了解输入文本框中下面提到的模板引用变量符号之间的区别.
<input type="text" name='name' ref-name [(ngModel)]='model'>
使用#name 和ref-name 有什么区别.
使用 ref-name 时变量的范围是否会发生变化?
有人可以建议最佳做法和理由吗?
它们是完全相同的两种不同的语法.
您可以这样想:有些人(和编辑)不喜欢新的#variable"语法,因此 Angular 提供了一个选项,可以使用更可口"的语法来使用完全相同的功能.>
I want to understand the difference between template reference variable notations as mentioned below in the input text boxes.
<input type="text" name='name' #name [(ngModel)]='model'>
<input type="text" name='name' ref-name [(ngModel)]='model'>
What's the difference between using #name and ref-name.
Does the scope of the variable changes on using ref-name ?
Can anybody please suggest the best practice and reason ?
They are two different syntaxes for literally exactly the same thing.
You can think of it this way: some people (and editors) don't like the new '#variable' syntax, so Angular provides an option to use the exact same functionality using a more 'palatable' syntax.
这篇关于模板引用变量(Angular 2)中的 ref- 前缀和 # 之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!