`value =" {{todo.title}}“和`[value] =”todo.title“之间有什么区别? [英] What's the difference between `value="{{todo.title}}"` and `[value]="todo.title"`?

查看:195
本文介绍了`value =" {{todo.title}}“和`[value] =”todo.title“之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Angular 2中做了一个todo应用程序来收集概念...
value ={{todo.title}} [value] =todo.title

I have been doing a todo app in Angular 2 to graps the concepts... What's the difference between value="{{todo.title}}" and [value]="todo.title"?

推荐答案

从Angular doc:


属性绑定或插值?

我们经常在插值和属性绑定之间有选择。以下绑定对执行相同的操作:

We often have a choice between interpolation and property binding. The following binding pairs do the same thing:

<p><img src="{{heroImageUrl}}"> is the <i>interpolated</i> image.</p>
<p><img [src]="heroImageUrl"> is the <i>property bound</i> image.</p>

<p><span>"{{title}}" is the <i>interpolated</i> title.</span></p>
<p>"<span [innerHTML]="title"></span>" is the <i>property bound</i> title.</p>

在许多情况下,插值是一种方便的属性绑定的替代方法。事实上,Angular将渲染视图之前将这些插值转换为相应的属性绑定。

Interpolation is a convenient alternative for property binding in many cases. In fact, Angular translates those interpolations into the corresponding property bindings before rendering the view.

没有技术原因可以选择一种形式到另一种形式。我们倾向于可读性,这往往倾向于内插。我们建议建立编码风格规则,并选择符合规则的表格,并为手头的任务感觉最自然。

There is no technical reason to prefer one form to the other. We lean toward readability, which tends to favor interpolation. We suggest establishing coding style rules and choosing the form that both conforms to the rules and feels most natural for the task at hand.

< a href =https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding =nofollow>链接

这篇关于`value =&quot; {{todo.title}}“和`[value] =”todo.title“之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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