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

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

问题描述

我想了解下面在输入文本框中提到的模板引用变量表示法之间的区别.

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'>

使用 #name ref-name 有什么区别.
变量的范围是否在使用ref-name时发生变化?
有人可以建议最佳做法和理由吗?

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.

您可以这样想:有些人(和编辑者)不喜欢新的"#variable"语法,因此Angular提供了使用更适口"语法使用完全相同的功能的选项.

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.

这篇关于模板引用变量(角度2)中的ref-前缀和#有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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