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

Angular2 + ag-Grid cannot load ag-grid-ng2/main.js (404 Not Found)

本文关键字:ag-Grid js Found main Not 加载 -ng2 Angular2      更新时间:2023-09-26

我正在尝试将ag-Grid与Angular2集成,但我被困在以下错误:

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

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

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

这是我的系统配置。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文件夹下看到依赖项:

感谢您的帮助

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

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

还要确保在node_modules包中有这些模块,否则确保在包中包含这些描述。