gpt4 book ai didi

angular - `value="{{todo.title} }"` 和 `[value]="todo.title"` 有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 17:37:09 24 4
gpt4 key购买 nike

我一直在用 Angular 2 做一个待办事项应用程序来掌握概念......value="{{todo.title}}"[value]="todo.title" 有什么区别?

最佳答案

来自 Angular 文档:

Property binding or interpolation?

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>

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.

Link

关于angular - `value="{{todo.title} }"` 和 `[value]="todo.title"` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com