How can I add bootstrap to Angular2 via system.js

前端 未结 2 1165
太阳男子
太阳男子 2021-01-04 11:06

I\'m trying to add bootstrap module to my ng2 application with by https://github.com/ng-bootstrap/ng-bootstrap. But all time getting this error:

It\'s my in

2条回答
  •  不知归路
    2021-01-04 11:57

    Your systemjs file should looks like this:

    var ngBootstrapMap = {
        '@ng-bootstrap/ng-bootstrap': '../lib/@ng-bootstrap/ng-bootstrap' //change the path according to your project structure
    }
    
    var ngBootstrapPackages = {
        '@ng-bootstrap/ng-bootstrap': { main: 'index.js', defaultExtension: 'js' }
    };
    
    var ngBootstrapPackageNames = [
        'accordion',
        'alert',
        'bundles',
        'buttons',
        'carousel',
        'collapse',
        'dropdown',
        'esm',
        'modal',
        'pagination',
        'popover',
        'progressbar',
        'rating',
        'tabset',
        'timepicker',
        'tooltip',
        'typeahead',
        'util'
    ];
    
    function ngBootstrapPackIndex(pkgName) {
        ngBootstrapPackages['@ng-bootstrap/ng-bootstrap/' + pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    
    ngBootstrapPackageNames.forEach(ngBootstrapPackIndex);
    
    var ngBootstrapConfig = {
        map: ngBootstrapMap,
        packages: ngBootstrapPackages
    };
    
    System.config(ngBootstrapConfig);
    

    Basically, it looks for index.js file in @ng-bootstrap/ng-bootstrap folder, and after for each component it looks index.js file in @ng-bootstrap/ng-bootstrap/{componentName}

    I hope it helps you

提交回复
热议问题