专栏首页Jerry的SAP技术分享Angular应用的依赖注入调试

Angular应用的依赖注入调试

上下文:我实现了一个hero service,在其构造函数里添加了一些打印语句:

在另一个Component的构造函数里将其注入:

运行时,观察service构造函数如何被调用的:

function getNodeInjectable(lView, tView, index, tNode) {
    let value = lView[index];
    const tData = tView.data;
    if (isFactory(value)) {
        const factory = value;
        if (factory.resolving) {
            throw new Error(`Circular dep for ${stringifyForError(tData[index])}`);
        }
        const previousIncludeViewProviders = setIncludeViewProviders(factory.canSeeViewProviders);
        factory.resolving = true;
        let previousInjectImplementation;
        if (factory.injectImpl) {
            previousInjectImplementation = setInjectImplementation(factory.injectImpl);
        }
        enterDI(lView, tNode);
        try {
            value = lView[index] = factory.factory(undefined, tData, lView, tNode);
            // This code path is hit for both directives and providers.
            // For perf reasons, we want to avoid searching for hooks on providers.
            // It does no harm to try (the hooks just won't exist), but the extra
            // checks are unnecessary and this is a hot path. So we check to see
            // if the index of the dependency is in the directive range for this
            // tNode. If it's not, we know it's a provider and skip hook registration.
            if (tView.firstCreatePass && index >= tNode.directiveStart) {
                ngDevMode && assertDirectiveDef(tData[index]);
                registerPreOrderHooks(index, tData[index], tView);
            }
        }
        finally {
            if (factory.injectImpl)
                setInjectImplementation(previousInjectImplementation);
            setIncludeViewProviders(previousIncludeViewProviders);
            factory.resolving = false;
            leaveDI();
        }
    }
    return value;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Apache2为什么会自动加载index.php

    我直接输入域名后,Apache2自动加载了对应目录下的index.php, 这是怎么做到的?

    Jerry Wang
  • RFC and session issue - why we should use DESTINATION NONE?

    在function module source code里有一个COMMIT WORK。

    Jerry Wang
  • Product Archive相关的标准function module

    版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)

    Jerry Wang
  • 几种常用的JS类定义方法

    // 方法1 对象直接量 var obj1 = { v1 : "", get_v1 : function() { return ...

    joshua317
  • Cannot use v-for on stateful component root element because it renders multiple elements.

    Cannot use v-for on stateful component root element because it renders multiple ...

    honey缘木鱼
  • 微软Build 2017首日总结:无处不在的云服务和AI

    镁客网
  • SpringBoot+MyBatis+Shiro 搭建杂谈

    一直想能仿公司框架的形式,着手做一个简单的脚手架,一来是带着目标性能更好地学习,接触新的技术,另外自己如果有什么想要实现的简单需求,就可以进行快速开发,主要还是...

    好好学java
  • FastDFS蛋疼的集群和负载均衡(十四)之Nginx+Tomcat负载均衡

    用户2032165
  • 深入理解 JavaScript 执行上下文和执行栈

    如果你是一名 JavaScript 开发者,或者想要成为一名 JavaScript 开发者,那么你必须知道 JavaScript 程序内部的执行机制。执行上下文...

    Fundebug
  • 跨平台编译-判断平台的预编译方法

    Pulsar-V

扫码关注云+社区

领取腾讯云代金券