小编Eut*_*epe的帖子

Angular 6自定义库没有ComponentFactoryResolver的提供程序

我从NG4-> NG6重写库(使用angular-cli 6)。这个lib改变了dynamicli的角度分量,所以我使用了ComponentFactoryResolver,在这里我卡住了。当我添加ComponentFactoryResolver到构造函数中时:

constructor(
    private componentFactoryResolver: ComponentFactoryResolver
) {}
Run Code Online (Sandbox Code Playgroud)

并在目标应用程序中构建lib(成功)(我从本地文件中将我的lib添加到package.json中)我遇到此错误:

StaticInjectorError(AppModule)[MyLibComponent-> ComponentFactoryResolver]: 
  StaticInjectorError(Platform: core)[MyLibComponent-> ComponentFactoryResolver]: 
    NullInjectorError: No provider for ComponentFactoryResolver!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)
    at resolveToken (core.js:1232)
    at tryResolveToken (core.js:1182)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
    at resolveToken (core.js:1232)
    at tryResolveToken (core.js:1182)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
    at resolveNgModuleDep (core.js:9238)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9919)
Run Code Online (Sandbox Code Playgroud)

没有ComponentFactoryResolver其他事情就可以正常工作

完整组成部分:

import { Component, ComponentFactoryResolver, AfterContentInit, ViewChild, Inject, Input, InjectionToken } from '@angular/core';

import { AbHostDirective } from './../directives/ab-host.directive';

export const AB_COMPONENTS = new InjectionToken('AB_COMPONENTS');

@Component({ …
Run Code Online (Sandbox Code Playgroud)

components dynamic angular-cli angular angular6

5
推荐指数
1
解决办法
2452
查看次数

标签 统计

angular ×1

angular-cli ×1

angular6 ×1

components ×1

dynamic ×1