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

时间:2017-02-15 22:51:54

标签: angularjs angular ag-grid ag-grid-ng2

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

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 /应用/组件/.../ mySecondEditorFrameworkComponent /我的 - 第二编辑器的框架-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.module

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

1 个答案:

答案 0 :(得分:0)

组件mySecondEditorFrameworkComponent不是模块,应放在declarations而不是imports