模板引用变量(Angular 2)中的 ref- 前缀和 # 之间有什么区别 [英] What's the difference between ref- prefix and # in Template reference variable (Angular 2)

查看:38
本文介绍了模板引用变量(Angular 2)中的 ref- 前缀和 # 之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解输入文本框中下面提到的模板引用变量符​​号之间的区别.

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

使用#nameref-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆