Angular2 + ag-Grid无法加载ag-grid-ng2 / main.js(404 Not Found)

时间:2016-09-21 14:46:12

标签: javascript angular systemjs ag-grid

我正在尝试将ag-Grid与Angular2集成,但我仍然坚持以下错误:

  

zone.js:101 GET http://localhost:4200/node_modules/ag-grid-ng2/main.js   404(未找到)

我正在使用以下方式导入第三方组件:

import {AgGridNg2} from 'ag-grid-ng2/main';
...
directives: [AgGridNg2]

这是我的 system-config.ts 文件:

"use strict";

// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  // ag libraries
  'ag-grid-ng2': 'node_modules/ag-grid-ng2',
  'ag-grid': 'node_modules/ag-grid',
  'ag-grid-enterprise' : 'node_modules/ag-grid-enterprise'
};

/** User packages configuration. */
const packages: any = {
  'ag-grid-ng2': {
    defaultExtension: "js"
  },
  'ag-grid': {
    defaultExtension: "js"
  },
  'ag-grid-enterprise': {
    defaultExtension: "js"
  }
};

////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
 * Everything underneath this line is managed by the CLI.
 **********************************************************************************************/
const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/forms',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',

  // Thirdparty barrels.
  'rxjs',

  // App specific barrels.
  'app',
  'app/shared',
  'app/full-width-renderer',
  /** @cli-barrel */
];

const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
  cliSystemConfigPackages[barrelName] = { main: 'index' };
});

/** Type declaration for ambient System. */
declare var System: any;

// Apply the CLI SystemJS configuration.
System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js'
  },
  packages: cliSystemConfigPackages
});

// Apply the user's configuration.
System.config({ map, packages });

我可以在 / node_modules / ag-grid-ng2 文件夹下看到依赖项:

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我还没有使用过企业网格,但是为了在Angular 2中使用ag-grid,你需要将它包含在System.config的map部分中:

'ag-grid': 'node_modules/ag-grid',
'ag-grid-ng2': 'node_modules/ag-grid-ng2'

另外,请确保在node_modules包中包含这些模块,否则请确保在package.json中包含这些说明并运行  npm install'第一