javascript - 使用 npm angular2 导入库

标签 javascript node.js angular typescript systemjs

我无法设置 this library使用 npm。

完成的命令:

npm install ng2-charts --save
npm install chart.js --save

index.html

我添加了这一行

        <script src="node_modules/chart.js/src/chart.js"></script>

app.module

        import { ChartsModule } from 'ng2-charts/ng2-charts';

    @NgModule({
      imports: [
        BrowserModule,
        RouterModule.forRoot(router),
        HttpModule,
        ChartsModule,

      ],

systemjs.config.js

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'chartJS':                   'npm:ng2-charts'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      chartJS:{
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

我的主机

console Error

localhost:3005/ng2-charts/ng2-charts 的内容实际上是一个 HTML 文件 - 它引用了我的 index.html

现在几个小时我都无法理解它是如何工作的。

最佳答案

你的 system.js 配置应该是,

  map: {
    'chart.js': 'npm:chart.js/dist/Chart.bundle.min.js',
     'ng2-charts': 'npm:ng2-charts'
  }

在包裹中,

 'ng2-charts': {
   main: 'ng2-charts.js',
   defaultExtension: 'js'
  }

关于javascript - 使用 npm angular2 导入库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44689352/

相关文章:

javascript - 将顶点法线转换为面法线

javascript - 错误: undefined in React useContext and useReducer

javascript - 尽管控制台显示值,但参数检查为空/未定义

javascript - 如何使用 Apple 的 UIAutomation JS 框架发出 Web 请求

node.js - fastify中如何组织路由?

mongodb - 我应该在node-mongodb-native中使用哪个ObjectID

angular - 我应该在每个路由器导航上重置我的 redux 存储吗?

angularjs - 谷歌位置下拉菜单并在 Angular 2 typescript 中绘制路线

javascript - 使用 CasperJS 计算 iFrame 中的每个元素

javascript - 如何以更简洁的方式编写嵌套订阅?