AngularJS:为什么NG-绑定优于{{}}在角? [英] AngularJS : Why ng-bind is better than {{}} in angular?

查看:122
本文介绍了AngularJS:为什么NG-绑定优于{{}}在角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在角presentation之一,而人在会议上提到的 NG-绑定更好{{之一}} 绑定。

I was in one of the angular presentation and one of the person in the meeting mentioned ng-bind is better than {{}} binding.

其一, NG-绑定之所以把变量观察名单,只有当有一个模型改变数据推送到视图中,另一方面, {{}} 每次(我猜是角的循环)插值前pression并推动价值,即使值改变与否。

One of the reason, ng-bind put the variable in the watch list and only when there is a model change the data get pushed to view, on the other hand, {{}} will interpolate the expression every time (I guess it is the angular cycle) and push the value, even if the value changed or not.

此外,它是说,如果你在屏幕上已经没有太多的数据,可以使用 {{}} 和性能问题将不可见。有人可以提供一些线索在这个问题上我吗?

Also it is said that, if you have not much data in on the screen you can use {{}} and the performance issue will not be visible. Can someone shed some light on this issue for me?

推荐答案

如果您不使用 NG-绑定,而不是像这样:

If you are not using ng-bind, instead something like this:

<div>
  Hello, {{user.name}}
</div>

您可能会看到实际的您好,{{user.name}} 为前 user.name 第二解决(在加载数据之前)

you might see the actual Hello, {{user.name}} for a second before user.name is resolved (before the data is loaded)

您可以做这样的事情。

<div>
  Hello, <span ng-bind="user.name"></span>
</div>

如果这是你的一个问题。

if that's an issue for you.

另一种解决方案是使用 NG-斗篷

Another solution is to use ng-cloak.

这篇关于AngularJS:为什么NG-绑定优于{{}}在角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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