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

标签 angularjs performance angular

在 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/

相关文章:

angularjs - Angular.js 过滤器的极性反转

javascript - 以 ES5 为目标时, typescript 编译输出 "import"

javascript - 返回 promise 后无法从 Controller 更新 View

mysql - MySQL 中的用户 ID 与用户名性能

java - 哪个对性能更好 - 对数据库进行批量调用或使用循环进行计算的单个调用?

javascript - 我想在我的应用程序中使用ng2-charts。尽管我已正确导入它,但仍然给我一个错误。找不到模块“ng2-charts/ng2-charts”

javascript - 设置 AngularJS 工厂来共享数据

javascript - WebGL 动画闪烁,对象太大?

javascript - 如何在 Angular 2中以YYYY-MM-DD格式获取日期

javascript - Angular 2 子路由