ag-grid-n2 导致无法解析编辑器组件的所有参数



我在Angular 2项目中为我的Ag-Grid声明了一些编辑帧组件。但是,当我在编辑器组件的构造函数中注入任何服务时,打字稿编译器加载网页时会引发以下错误:

Uncaught Error: Can't resolve all parameters for MyOtherEditorFrameworkComponent: (?)
  at CompileMetadataResolver.getDependenciesMetadata (http://<rooturl here>/main.bundle.js:39398:19)
    at CompileMetadataResolver.getTypeMetadata (http://<rooturl here>/main.bundle.js:39299:26)
    at CompileMetadataResolver.getDirectiveMetadata (http://<rooturl here>/main.bundle.js:39074:28)
    at http://<rooturl here>/main.bundle.js:39167:49
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (http://<rooturl here>/main.bundle.js:39161:49)
    at RuntimeCompiler._compileComponents (http://<rooturl here>/main.bundle.js:57492:47)
    at RuntimeCompiler._compileModuleAndComponents (http://<rooturl here>/main.bundle.js:57430:37)
    at RuntimeCompiler.compileModuleAsync (http://<rooturl here>/main.bundle.js:57421:21)
    at PlatformRef_._bootstrapModuleWithZone (http://<rooturl here>/main.bundle.js:41293:25)

我通过声明组件的模块并在app.module中宣布模块来解决另一个需要注入服务的编辑器组件的问题。但是,这似乎对第二个编辑器组件不起作用,如果我添加了下面在App.Module中类似定义的第二个编辑器组件与第一个编辑器组件模块。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MyOtherEditorFrameworkComponent} from './my-other-editor-framework.component';
@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [MyOtherEditorFrameworkComponent]
})
export class MyOtherEditorFrameworkModule{ }

src/app/components/.../mySecondeTorFrameWorkComponent/my-second-editor-editor-editor-framework-component.ts

>
import { Component, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { AgEditorComponent } from 'ag-grid-ng2/main';
import { MyInjectedService } from '../../../services/myinjectedservice/my-injected.service';
@Component({
  selector: 'app-name-editor',
  templateUrl: './name-editor.component.html',
  styleUrls: ['./name-editor.component.sass']
})
export class mySecondEditorFrameworkComponent implements OnInit, AgEditorComponent {
@ViewChild('mySecondEditor', { read: ViewContainerRef }) mySecondEditor;
constructor(private myInjectedService : MyInjectedService ) { }
 ...}

src/app/app.module

@NgModule({ 
    imports: [
        AgGridModule.withNg2ComponentSupport(),
        MyOtherEditorFrameworkModule,
        //MySecondEditorFrameworkModule, //<-- this throws the error
        ...],
     ...
     providers: [ myInjectedService]
     })

组件mySecondEditorFrameworkComponent不是模块,应将其放在declarations而不是imports中。

最新更新