首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用npm angular2导入库

使用npm angular2导入库
EN

Stack Overflow用户
提问于 2017-06-22 02:53:10
回答 1查看 64关注 0票数 2

我无法使用npm设置这个图书馆

命令完成:

代码语言:javascript
复制
npm install ng2-charts --save
npm install chart.js --save

index.html

我加了这一行

代码语言:javascript
复制
        <script src="node_modules/chart.js/src/chart.js"></script>

app.module

代码语言:javascript
复制
        import { ChartsModule } from 'ng2-charts/ng2-charts';

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

      ],

systemjs.config.js

代码语言:javascript
复制
(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);

我的控制台

这个localhost:3005/ng2-charts/ng2-charts的内容实际上是一个index.html文件,它指的是我的index.html

我几个小时都搞不懂它是怎么工作的。

EN

回答 1

Stack Overflow用户

发布于 2017-06-22 02:57:32

你的system.js配置应该是

代码语言:javascript
复制
  map: {
    'chart.js': 'npm:chart.js/dist/Chart.bundle.min.js',
     'ng2-charts': 'npm:ng2-charts'
  }

在包裹里,

代码语言:javascript
复制
 'ng2-charts': {
   main: 'ng2-charts.js',
   defaultExtension: 'js'
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44689352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档