更新DOM VS重新描绘的视图在角 [英] Update the DOM vs Rerender the View In Angular

查看:168
本文介绍了更新DOM VS重新描绘的视图在角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面 https://docs.angularjs.org/guide/scope

5,$观察名单检测name属性的改变并通知插值,这反过来又更新了DOM。

5.The $watch list detects a change on the name property and notifies the interpolation, which in turn updates the DOM.

6.Angular退出执行上下文,这反过来又离开keydown事件,并与它的JavaScript执行上下文

6.Angular exits the execution context, which in turn exits the keydown event and with it the JavaScript execution context.

7. 浏览器重新呈现与更新文本视图

我有疑问,是什么之间的differnce 更新DOM 在5号线和浏览器重新呈现第7行的看法
先谢谢了。

I am having doubt what is the differnce between updates the DOM on Line 5 and browser re-renders the view on line 7. Thanks In advance.

推荐答案

在DOM重新presents在浏览器加载HTML文档。 JavaScript可以操纵通过DOM文档,但那些操作不JavaScript的背景下,更改了DOM完成后立即但只有生效。

The DOM represents the HTML document loaded in the browser. JavaScript can manipulate the document through the DOM, but those manipulations do not take effect immediately but only after the JavaScript context that makes changes to the DOM is finished.

想想这种方式:


      
  • JS​​:嘿HTML文档,我会做一些改变您

  •   
  • HTML:好的,去吧,请联系您的朋友DOM并告诉他你想改变什么

  •   
  • JS​​:OK,我就可以了...

  •   
  • JS​​:OK,我做了一些改变,但是,嘿,还有一些事情,我需要改变

  •   
  • HTML:好的,去吧,我会等到你完成一切

  •   
  • JS​​:OK,一切完成

  •   
  • HTML:好了,我会问DOM你改变了什么,并应用这些

  •   

考虑以下测试:

var a = document.body.children[0];

a.style.color = 'red'; 
for(var i = 0; i < 10000000000; i++) { }; 
a.style.color = 'blue';

虽然有指令之间相当长的时间来改变颜色为红色,一个将其更改为蓝色,你永远不会看到的颜色会变为红色,因为一旦JS完成了所有的改变将被应用。

Although there's considerable time between the instruction to change the color to red and the one to change it to blue, you will never see the color changing to red because all changes will be applied once the JS finished.

在实际上,颜色不变成红色,但只为如此短的时间周期它变为蓝色,该浏览器甚至没有时间来呈现的改变之前。或者,如果是,你不会注意到。

In fact, the color does change to red but only for such a short time period before it's changing to blue that the browser doesn't even have time to render the change. Or if it is, you won't notice.

在换句话说,DOM操作是由浏览器中排队。一旦JS背景下完成的队列将被执行。如果JavaScript的花费在其他任务2 DOM变化之间的时间,将延迟队列执行开始,然后所有排队的变化将很大陆续执行。

In other words, DOM manipulations are queued by the browser. The queue will be executed once the JS context is finished. If JavaScript spends time between 2 DOM changes on other tasks, that will delay the start of the queue execution and then all queued changes will be executed in great succession.

在上述信息光,它应该很清楚,改变DOM是不一样的东西改变HTML文档。

In light of the above information, it should become clear that changing the DOM is not the same thing as changing the HTML document.

这篇关于更新DOM VS重新描绘的视图在角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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