Как использовать ngx-bootstrap в приложении Angular 4 с модульной системой SystemJs

Я испробовал множество вариантов указания пути, позволяющего SystemJS загружать пакет ngx-bootstrap.

    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 

wrapFn@http://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"

person David Chelliah    schedule 03.05.2017    source источник


Ответы (1)


Вам не хватает этой части:

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

person Tiep Phan    schedule 03.05.2017
comment
Ваше решение верное. Но с начальным проектом Angular... Мне нужно, чтобы он был project.config.ts, как показано ниже let additionalPackages: ExtendPackages[] = [{ name: 'ngx-bootstrap', path: 'node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.min.js' }, { name: 'highcharts', path: 'node_modules/highcharts/highcharts.js' }, { name: 'angular2-highcharts', path: 'node_modules/angular2-highcharts/index.js' }]; this.addPackagesBundles(additionalPackages); - person David Chelliah; 04.05.2017
comment
Добавление только «ngx-bootstrap»: «node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.js» под объявлением карты сработало для меня без дополнительного объявления пакета. - person Taf; 09.05.2017