2017-05-03 41 views
5

我已经尝试了指定路径的许多变化允许SystemJS加载NGX的自举包如何使用与SystemJs模块系统角4应用NGX-引导

System.config({ 
    "defaultJSExtensions": true, 
    "paths": { 

     "@angular/core": "node_modules/@angular/core/bundles/core.umd.js", 
     "@angular/forms": "node_modules/@angular/forms/bundles/forms.umd.js", 
     "@angular/http": "node_modules/@angular/http/bundles/http.umd.js", 
     ... 
     "*": "node_modules/*", 
     "ngx-bootstrap": "node_modules/ngx-bootstrap", 
     "highcharts": "node_modules/highcharts/highcharts.js", 
     "angular2-highcharts": "node_modules/angular2-highcharts/index.js" 
    }, 
    "packages": {} 
}); 

但它仍然不会加载正确..

我在控制台中看到以下错误

"(SystemJS) XHR error (404 Not Found) loading http://localhost:5555/node_modules/ngx-bootstrap.js 

[email protected]://localhost:5555/node_modules/zone.js/dist/zone.js?1493823577322:1230:30 [<root>]  

Error loading http://localhost:5555/node_modules/ngx-bootstrap.js as "ngx-bootstrap" from http://localhost:5555/hc/app.module.js" 

"Not expecting this error? Report it at https://github.com/mgechev/angular-seed/issues" 

回答

5

你缺少这一部分:

packages: { 
    //... other code 
    'ngx-bootstrap': { format: 'cjs', main: 'bundles/ngx-bootstrap.umd.js', defaultExtension: 'js' }, 
} 

此处演示:https://github.com/valor-software/angular2-quickstart/blob/e9ea3dfd6ea48acf40a99e8e0ab1c9908f3467cd/systemjs.config.js#L22

+1

您的解决方案是正确的。但是,通过Angular种子项目...我需要它到project.config.ts,如下所示,让我们在下面的例子中使用'let additionalPackages:ExtendPackages [] = ['ngx-bootstrap', path:'node_modules/ngx-bootstrap/bundles /ngx-bootstrap.umd.min.js' },{ 名: 'highcharts', 路径: 'node_modules/highcharts/highcharts.js' },{ 名: 'angular2-highcharts', 路径:'node_modules/angular2-highcharts/index.js' }]; this.addPackagesBundles(additionalPackages);' –

+1

只需在映射声明下添加'ngx-bootstrap':'node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.js'就可以工作,而无需执行额外的包声明。 – Taf