Importing D3.js into Angular 2

I just migrated from php to Angular 2, without much experience with javascript or typescript. So I need your help filling the gap.

I am working on a rather large application where I need to use D3.js. My development app is built on top of the official quickstart ( https://github.com/angular/quickstart ).

I'm trying to import d3-ng2-service ( https://www.npmjs.com/package/d3-ng2-service ) and as far as I read on SO and github the code is correct. However, this will not work. Here's the code below, edited for brevity.

src / app / app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { HttpModule, JsonpModule }    from '@angular/http';

import { FileUploadModule } from 'ng2-file-upload';
import { D3Service } from 'd3-ng2-service';

*...*

@NgModule({
  imports: [ 
    BrowserModule, 
    FormsModule,
    HttpModule,
    JsonpModule,
    FileUploadModule,
    *...*
  ],
  declarations: [ 
    *...*
  ],
  providers: [  
    D3Service,
  ],
  bootstrap: [ 
    *...*
  ]
})

export class AppModule { }

      

Csi / systemjs.config.js

(function (global) {
  System.config({
    paths: {
      'npm:': 'node_modules/'
    },
    map: {
      'app': 'app',
      '@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',

      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',

      'ng2-file-upload' : 'npm:ng2-file-upload',
      'd3-ng2-service' : 'npm:d3-ng2-service', 
    },
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      },
      /** Configuration for ng2-file-upload */
      'ng2-file-upload' : { 
        main: './ng2-file-upload.js',
        defaultExtension: 'js'
      },
      'd3-ng2-service' : { 
        main: './index.js',
        defaultExtension: 'js'
      },
    }
  });
})(this);

      

The error I get in the console is this:

GET http://localhost:3000/traceur 404 (Not Found)
Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur
    Error: XHR error (404 Not Found) loading http://localhost:3000/traceur
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:1075:39)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:191:47)
        at ZoneTask.invokeTask [as invoke] (http://localhost:3000/node_modules/zone.js/dist/zone.js:498:34)
        at invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:1370:14)
        at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3000/node_modules/zone.js/dist/zone.js:1388:17)
    Error loading http://localhost:3000/traceur
    Unable to load transpiler to transpile http://localhost:3000/node_modules/d3-ng2-service/index.js
    Error loading http://localhost:3000/node_modules/d3-ng2-service/index.js as "d3-ng2-service" from http://localhost:3000/app/app.module.js
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:1075:39)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:191:47)
        at ZoneTask.invokeTask [as invoke] (http://localhost:3000/node_modules/zone.js/dist/zone.js:498:34)
        at invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:1370:14)
        at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3000/node_modules/zone.js/dist/zone.js:1388:17)
    Error loading http://localhost:3000/traceur
    Unable to load transpiler to transpile http://localhost:3000/node_modules/d3-ng2-service/index.js
    Error loading http://localhost:3000/node_modules/d3-ng2-service/index.js as "d3-ng2-service" from http://localhost:3000/app/app.module.js

      

I can confirm that all paths are correct. There is one statement in node_modules / d3-ng2-service / index.js:

export * from './src/d3.service';

      

Do I need some additional dependencies to read this statement? I am not using webpack and d3-ng2-service does not prove the .umd entry point.

+3


source to share





All Articles