_zone.onMicrotaskEmpty的触发起始位置:

class ApplicationRef {/** @internal */constructor(_zone, _console, _injector, _exceptionHandler, _componentFactoryResolver, _initStatus) {this._zone = _zone;this._console = _console;this._injector = _injector;this._exceptionHandler = _exceptionHandler;this._componentFactoryResolver = _componentFactoryResolver;this._initStatus = _initStatus;/** @internal */this._bootstrapListeners = [];this._views = [];this._runningTick = false;this._enforceNoNewChanges = false;this._stable = true;/*** Get a list of component types registered to this application.* This list is populated even before the component is created.*/this.componentTypes = [];/*** Get a list of components registered to this application.*/this.components = [];this._enforceNoNewChanges = isDevMode();this._zone.onMicrotaskEmpty.subscribe({next: () => {this._zone.run(() => {this.tick();});}});

tick方法的实现会调用视图view的detectChange方法:

/*** Invoke this method to explicitly process change detection and its side-effects.** In development mode, `tick()` also performs a second change detection cycle to ensure that no* further changes are detected. If additional changes are picked up during this second cycle,* bindings in the app have side-effects that cannot be resolved in a single change detection* pass.* In this case, Angular throws an error, since an Angular application can only have one change* detection pass during which all change detection must complete.*/tick() {if (this._runningTick) {throw new Error('ApplicationRef.tick is called recursively');}try {this._runningTick = true;for (let view of this._views) {view.detectChanges();}if (this._enforceNoNewChanges) {for (let view of this._views) {view.checkNoChanges();}}}catch (e) {// Attention: Don't rethrow as it could cancel subscriptions to Observables!this._zone.runOutsideAngular(() => this._exceptionHandler.handleError(e));}finally {this._runningTick = false;}}

递归调用refreshView:

refreshView里执行view template:

从调试器里能看出template所属的host DOM element,在这个例子里是UnitDetailsComponent内的cx-org-card标签里第一个div元素:

这里待执行的setter的property和value都已经自动生成了:

这里的highlight似乎有问题,应该是第三行被highlight才对:


function ngOnChangesSetInput(instance, value, publicName, privateName) {const simpleChangesStore = getSimpleChangesStore(instance) ||setSimpleChangesStore(instance, { previous: EMPTY_OBJ, current: null });const current = simpleChangesStore.current || (simpleChangesStore.current = {});const previous = simpleChangesStore.previous;const declaredName = this.declaredInputs[publicName];const previousChange = previous[declaredName];current[declaredName] = new SimpleChange(previousChange && previousChange.currentValue, value, previous === EMPTY_OBJ);instance[privateName] = value;
}

instance:FocusDirective

这个__ngSimpleChanges__应该不能被应用程序使用:


更多Jerry的原创文章,尽在:“汪子熙”:

Angular的_zone.onMicrotaskEmpty最终会通过changeDetect重新刷新视图相关推荐

  1. angular 强制更新视图_angular4强制刷新视图的方法

    angular4强制刷新视图的方法 使用angular的过程中有时会出现数据已经更新了,但是对于的视图没有更新,针对这一情况,可以是用angular提供的方法强制更新视图. 这里使用NGZone来更新 ...

  2. Angular 项目打包之后,部署到服务器,刷新访问404解决方法

    将前端代码打包部署到Java服务器中,当跳转到相应路由界面,刷新地址,服务找不到地址页面,所以会报   404 - Page Not Found. 解决方法:只需要将路由转换成哈希值: userHas ...

  3. 使用百度echarts制作可视化大屏——最终效果和动态数据刷新

    最终效果如下图: 接下来就是数据动态刷新了,这个没什么好说的,就是一个$.post的事,传递一个json给自定义的refresh函数就行了. $.post(url,null,function(d){ ...

  4. angular 强制刷新视图

    使用angular的过程中有时会出现数据已经更新了,但是对于的视图没有更新,针对这一情况,可以是用angular提供的方法强制更新视图. import { Component, OnInit } fr ...

  5. Angular 变化检测详解

    作者:PingCode 产品研发部研发二组负责人王凯 前言 变化检测是前端框架中很有趣的一部分内容,各个前端的框架也都有自己的一套方案,一般情况下我们不太需要过多的了解变化检测,因为框架已经帮我们完成 ...

  6. Angular property binding重复触发的问题讨论

    Component template文件源代码: <button [disabled]="isDisabled" >Click me</button> Co ...

  7. Angular 个人深究(三)【由InputOutput引起的】

    Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...

  8. angular react_Angular 2 vs React:将会有鲜血

    angular react Angular 2 has reached Beta and appears poised to become the hot new framework of 2016. ...

  9. angular java_带有Angular JS的Java EE 7 –第1部分

    angular java 今天的帖子将向您展示如何使用Java EE 7和Angular JS构建一个非常简单的应用程序. 在去那里之前,让我告诉您一个简短的故事: 我必须承认,我从来都不是Java语 ...

最新文章

  1. Elasticsearch——分词器对String的作用
  2. java dozer map转对象_对象转换利器之Dozer
  3. c语言编程分数判定,用C语言编程平均分数
  4. python免费领取视频-quot;免费领取Python资源”
  5. Visual Studio 2012正式版官方下载地址
  6. 孙燕姿:(Hello, I'm Stefanie...)
  7. 微信小程序+vant Weapp Slider 滑块实现滑动拖动计数器
  8. 住宅内部通信系统市场现状研究分析与发展前景预测报告
  9. 微信订阅号服务器配置url如何配置,微信订阅号开发模式基本配置
  10. 什么人不可以喝普洱熟茶?
  11. 蜕变的过程总是痛苦的
  12. 关于如何打破传统阅读体验的一些想法
  13. linux:ping不通www.baidu.com
  14. c语言程序设计的实验报告,C语言程序设计实验报告
  15. visio模板#科研绘图#visio#技术路线图#文献汇报思路
  16. 让每个人都拥有富足的人生,GSN重新定义社交经济
  17. Android: 进程保活
  18. 赛迪智库 | 2019年下半年中国虚拟现实产业走势分析与判断
  19. 提醒工作的电脑闹钟软件用哪个?
  20. 最简单DIY蓝牙PS2遥控器控制蓝牙智能小车

热门文章

  1. 1027. 打印沙漏(20)
  2. oVirt Reports Portal 3.4 added to ovirt-engine
  3. java 的HashMap底层数据结构
  4. 前端开发总结--之关于FusionSphere WEBUI的想法
  5. 用Syslog 记录UNIX和Windows日志的方法
  6. 一份详细的服务器安全解决方案
  7. js中document.referrer认识
  8. 关于vue搭建项目运行出行的错误问题,简直是大坑啊
  9. AES加密,加签验签
  10. 高德地图JavaScript API开发研究