同ngOnChanges hook的调用入口一致,请查看这篇文章:fixture.detectChange开始单步调试,如何执行到Directive的ngOnChange钩子.

refreshView是一个逻辑很多的函数:

/*** Processes a view in update mode. This includes a number of steps in a specific order:* - executing a template function in update mode;* - executing hooks;* - refreshing queries;* - setting host bindings;* - refreshing child (embedded and component) views.*/
function refreshView(tView, lView, templateFn, context) {ngDevMode && assertEqual(isCreationMode(lView), false, 'Should be run in update mode');const flags = lView[FLAGS];if ((flags & 256 /* Destroyed */) === 256 /* Destroyed */)return;enterView(lView, lView[T_HOST]);const checkNoChangesMode = getCheckNoChangesMode();try {resetPreOrderHookFlags(lView);setBindingIndex(tView.bindingStartIndex);if (templateFn !== null) {executeTemplate(tView, lView, templateFn, 2 /* Update */, context);}const hooksInitPhaseCompleted = (flags & 3 /* InitPhaseStateMask */) === 3 /* InitPhaseCompleted */;// execute pre-order hooks (OnInit, OnChanges, DoCheck)// PERF WARNING: do NOT extract this to a separate function without running benchmarksif (!checkNoChangesMode) {if (hooksInitPhaseCompleted) {const preOrderCheckHooks = tView.preOrderCheckHooks;if (preOrderCheckHooks !== null) {executeCheckHooks(lView, preOrderCheckHooks, null);}}else {const preOrderHooks = tView.preOrderHooks;if (preOrderHooks !== null) {executeInitAndCheckHooks(lView, preOrderHooks, 0 /* OnInitHooksToBeRun */, null);}incrementInitPhaseFlags(lView, 0 /* OnInitHooksToBeRun */);}}// First mark transplanted views that are declared in this lView as needing a refresh at their// insertion points. This is needed to avoid the situation where the template is defined in this// `LView` but its declaration appears after the insertion component.markTransplantedViewsForRefresh(lView);refreshEmbeddedViews(lView);// Content query results must be refreshed before content hooks are called.if (tView.contentQueries !== null) {refreshContentQueries(tView, lView);}// execute content hooks (AfterContentInit, AfterContentChecked)// PERF WARNING: do NOT extract this to a separate function without running benchmarksif (!checkNoChangesMode) {if (hooksInitPhaseCompleted) {const contentCheckHooks = tView.contentCheckHooks;if (contentCheckHooks !== null) {executeCheckHooks(lView, contentCheckHooks);}}else {const contentHooks = tView.contentHooks;if (contentHooks !== null) {executeInitAndCheckHooks(lView, contentHooks, 1 /* AfterContentInitHooksToBeRun */);}incrementInitPhaseFlags(lView, 1 /* AfterContentInitHooksToBeRun */);}}setHostBindingsByExecutingExpandoInstructions(tView, lView);// Refresh child component views.const components = tView.components;if (components !== null) {refreshChildComponents(lView, components);}// View queries must execute after refreshing child components because a template in this view// could be inserted in a child component. If the view query executes before child component// refresh, the template might not yet be inserted.const viewQuery = tView.viewQuery;if (viewQuery !== null) {executeViewQueryFn(2 /* Update */, viewQuery, context);}// execute view hooks (AfterViewInit, AfterViewChecked)// PERF WARNING: do NOT extract this to a separate function without running benchmarksif (!checkNoChangesMode) {if (hooksInitPhaseCompleted) {const viewCheckHooks = tView.viewCheckHooks;if (viewCheckHooks !== null) {executeCheckHooks(lView, viewCheckHooks);}}else {const viewHooks = tView.viewHooks;if (viewHooks !== null) {executeInitAndCheckHooks(lView, viewHooks, 2 /* AfterViewInitHooksToBeRun */);}incrementInitPhaseFlags(lView, 2 /* AfterViewInitHooksToBeRun */);}}if (tView.firstUpdatePass === true) {// We need to make sure that we only flip the flag on successful `refreshView` only// Don't do this in `finally` block.// If we did this in `finally` block then an exception could block the execution of styling// instructions which in turn would be unable to insert themselves into the styling linked// list. The result of this would be that if the exception would not be throw on subsequent CD// the styling would be unable to process it data and reflect to the DOM.tView.firstUpdatePass = false;}// Do not reset the dirty state when running in check no changes mode. We don't want components// to behave differently depending on whether check no changes is enabled or not. For example:// Marking an OnPush component as dirty from within the `ngAfterViewInit` hook in order to// refresh a `NgClass` binding should work. If we would reset the dirty state in the check// no changes cycle, the component would be not be dirty for the next update pass. This would// be different in production mode where the component dirty state is not reset.if (!checkNoChangesMode) {lView[FLAGS] &= ~(64 /* Dirty */ | 8 /* FirstLViewPass */);}if (lView[FLAGS] & 1024 /* RefreshTransplantedView */) {lView[FLAGS] &= ~1024 /* RefreshTransplantedView */;updateTransplantedViewCount(lView[PARENT], -1);}}finally {leaveView();}
}

从refreshView函数调用hook的顺序来看,ngOnChanges hook的执行一定先于ngAfterViewInit:

fixture.detectChange开始单步调试,如何执行到Directive的ngAfterViewInit钩子相关推荐

  1. fixture.detectChange开始单步调试,如何执行到Directive的ngOnChange钩子

    this._tick里调用this.changeDetectorRef.detectChanges(): 首先从RootViewRef开始检测: context里能看到Component的数据: re ...

  2. Angular jasmine如何从detectChange触发refreshView进而执行到Component的hook实现

    触发RefreshView: refreshView的方法实现里,会多处调用executeCheckHook方法: 每个待执行的hook方法的名称都能在注释里找到: 例如:execute pre-or ...

  3. Python如何实现单步调试

    Python如何实现单步调试 https://www.cnblogs.com/jing1617/p/9396617.html https://www.cnblogs.com/xiaohai2003ly ...

  4. 从ngrx store里selector出来的Observable,执行subscribe的单步调试

    源代码: getNextPageContext(): Observable<PageContext> {const a = this.store.pipe(select(RoutingSe ...

  5. linux下gdb单步调试

    用 GDB调试程序 GDB 概述 ---- GDB 是 GNU开源组织发布的一个强大的 UNIX下的程序调试工具.或许,各位比较喜欢那种图形界面方式的,像 VC. BCB等 IDE的调试,但如果你是在 ...

  6. ARM DS-5单步调试ARM64 linux 内核

    目录 1 介绍 2 开发环境 3 准备工作 3.1 Ubuntu环境准备 3.2 源代码准备 3.3 DS-5准备 3.4 使用DS-5调试源码 3.4.1 建立源码工程 3.4.2 创建debug配 ...

  7. C语言简单的单步调试

    C语言中的单步跟踪调试 单步调试是指程序开发中,为了找到程序的bug,通常采用的一种调试手段,一步一步跟踪程序执行的流程,根据变量的值,找到错误的原因. 下面以一个简单的小程序为例,这里的程序必须是在 ...

  8. java的单步调试_Eclipse调试Java程序 可用于单步调试

    在Eclipse中交互式运行代码是其最强大的特性之一,使用JDT调试器,你可以逐行执行你的Java程序,检查程序不同位置变量的值,这个过程在定位代码中的问题时非常有用. 为了准备调试,你需要在代码中设 ...

  9. c语言 vc 单步调试方法,VC6断点调试技巧

    在第一篇中,我们为大家介绍了如何用VC6进行断点调试,可以实现程序的分步执行.今天我们将继续深入,进行更多断点调试的学习. 首先,写一个例子程序: #include int fun() { print ...

最新文章

  1. hexo博客更新主题后上传Git操作
  2. 解决ms_cannot_allocmem错误的两种方法
  3. 阿里云Ubuntu安装图形界面与中文语言包
  4. 前端面试题--重要基础知识回顾(一)
  5. 粒子群算法求解带约束优化问题 源码实现
  6. django实现web分页的三种方法
  7. DenseNet细节
  8. EverWeb for Mac(网页设计软件)v3.5.1中文版
  9. c# 利用t4模板,自动生成Model类
  10. tomcat中开启SSL
  11. linux snap文件夹,在Linux下使用Snap安装Rambox的方法
  12. 覆盖率测试工具gcov的前端工具_LCOV_简介
  13. Julia : Set or Array ?
  14. html链接安装包,磁力宅资源链接地址
  15. 《App后台开发运维和架构实践》前言
  16. 乐优商场项目day08——图片(文件)上传
  17. python爬虫爬取微信公众号的阅读数、喜爱数、文章标题和链接等信息
  18. win10关闭电池保护模式_怎么设置win10电池95%不充电
  19. 一款网页游戏外挂开发-数据抓包2
  20. 分机计算机怎么设置共享打印机,win7打印机共享设置分机怎么设置

热门文章

  1. 图解HashMap(一)
  2. 2014年Spark亚太峰会参与回忆录
  3. 设计模式之四(抽象工厂模式第三回合)
  4. android onNewIntent
  5. Delphi数据类型
  6. Stack around the variable 'date' was corrupted.
  7. 消除电脑的四大噪音源
  8. 多线程编程学习笔记——任务并行库(三)
  9. Delphi调用外部程序的集中方法
  10. Android的Touch系统简介(一)