意外的价值' undefined'由模块导入的AppModule' ngModule中的错误?

时间:2016-09-13 16:07:37

标签: angular ag-grid

我正在使用ngModule对导入和其他依赖项进行分组。我使用ag网格作为数据网格。下面是我的app.module.ts -

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {SecurityContextService} from './securitycontext.service';
import { AppComponent }  from './app.component';
import { HttpModule } from '@angular/http';
import {AgGridModule} from 'ag-grid-ng2/main';
import {HeaderComponent} from './app.header';
@NgModule({
  imports: [ BrowserModule,HttpModule,AgGridModule],
  declarations: [ AppComponent,HeaderComponent],
  providers: [  SecurityContextService],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

我得到了下面提到的例外。

  

意外的价值'未定义'由模块' AppModule'

导入

以下是异常的堆栈跟踪 -

  

错误:错误:意外的值'未定义'由模块导入   '的AppModule'在新的BaseException   (http://localhost:8000/lib/@angular/compiler/src/facade/exceptions.js:27:23)   在eval   (http://localhost:8000/lib/@angular/compiler/src/metadata_resolver.js:255:31)   在Array.forEach(native)at   CompileMetadataResolver.getNgModuleMetadata   (http://localhost:8000/lib/@angular/compiler/src/metadata_resolver.js:239:44)   在RuntimeCompiler._compileComponents   (http://localhost:8000/lib/@angular/compiler/src/runtime_compiler.js:150:47)   在RuntimeCompiler._compileModuleAndComponents   (http://localhost:8000/lib/@angular/compiler/src/runtime_compiler.js:72:37)   在RuntimeCompiler.compileModuleAsync   (http://localhost:8000/lib/@angular/compiler/src/runtime_compiler.js:49:21)   在PlatformRef _._ bootstrapModuleWithZone   (http://localhost:8000/lib/@angular/core/src/application_ref.js:368:25)   在PlatformRef_.bootstrapModule   (http://localhost:8000/lib/@angular/core/src/application_ref.js:361:21)   at execute(http://localhost:8000/app/main.js:16:65)加载错误   http://localhost:8000/app/main.js

注意:只有在我的导入中使用 AgGridModule 时才会出现此异常。

我正在使用gulp来构建我的应用程序。

修改

下面是Systemjs.config -

// map tells the System loader where to look for things
var map = {
    'app': 'app', // 'dist',
    'rxjs': 'lib/rxjs',
    '@angular': 'lib/@angular',
    'ag-grid-ng2': 'lib/ag-grid-ng2',
    'ag-grid-enterprise': 'lib/ag-grid-enterprise',
    'ag-grid': 'lib/ag-grid',
     '@angular/router':  'lib/@angular/router',
     'angular2-in-memory-web-api': 'lib/angular2-in-memory-web-api',
};

// packages tells the System loader how to load when no filename and/or no extension
var packages = {
    'app': {main: 'main.js', defaultExtension: 'js'},
    'rxjs': {defaultExtension: 'js'},
     'ag-grid-ng2': {
        defaultExtension: "js"
    },
    'ag-grid': {
        defaultExtension: "js"
    },
    'ag-grid-enterprise': {
        defaultExtension: "js"
    },
    'angular2-in-memory-web-api': {
                main: './index.js',
                defaultExtension: 'js'
            },
};

var packageNames = [
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/http',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router',
    '@angular/router-deprecated',
    '@angular/testing',
    '@angular/upgrade',
    '@angular/forms'
];

// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function (pkgName) {
    packages[pkgName] = {main: 'index.js', defaultExtension: 'js'};
});

var config = {
    map: map,
    packages: packages
};

// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) {
    global.filterSystemConfig(config);
}

System.config(config);

1 个答案:

答案 0 :(得分:0)

我不完全确定这会解决您的问题,但如果您使用ag2格式的ng2,那么您需要按如下方式提取AgGridModule:

@NgModule({
imports: [
    BrowserModule,
    AgGridModule.forRoot(),
    ...
})

forRoot位在那里,以便客户不必在根级别声明模块。

相关问题