gpt4 book ai didi

angularjs - 插值 {{}} 和 [innerText] 之间的性能差异 - Angular 2

转载 作者:太空狗 更新时间:2023-10-29 17:45:38 25 4
gpt4 key购买 nike

在 Angular 1 中,使用 ng-bind 可以提高插值性能。

在 Angular 2 中仍然是这种情况吗?我应该使用 [innerText] 而不是插值。

例如

<p>{{slower}}</p>
<p [innerText]="faster"></p>

最佳答案

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

Interpolated: <img src="{{vehicle.imageUrl}}"><br>
Property bound: <img [src]="vehicle.imageUrl">

The interpolated title is {{title}}

[innerHTML]="'The [innerHTML] title is '+title">

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.

来源:https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding

所以你可以使用任何人。希望这会帮助你。

关于angularjs - 插值 {{}} 和 [innerText] 之间的性能差异 - Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783729/

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