使用d3.js

时间:2017-08-07 14:14:39

标签: angular d3.js svg

我正在尝试在Angular 2中使用简单的d3.js方法d3.xml,因此我可以将.svg文件的内容加载到我的html模板中。我的组件的相关代码如下:

    import { Component, OnInit } from '@angular/core';

    import { D3Service, D3, Selection } from 'd3-ng2-service';

    @Component({
        selector: 'ContentPhotos',
        templateUrl: './content-photos.component.html',
        styleUrls:['./content-photos.component.css'],
    })

    export class ContentPhotosComponent implements OnInit {

      private d3: D3;

      constructor(
        d3Service: D3Service,
      ){
        this.d3 = d3Service.getD3();
      }

      ngOnInit() {
        let d3 = this.d3;

        d3.xml(this.layout.url).mimeType("image/svg+xml").get(function(error, xml) {
          if (error) throw error;
          console.log(xml.documentElement);
        });
      }
    }

但是我无法在Angular中使用它。它说

Property 'xml' does not exist on type 'typeof "C:/wamp64/www/angular-cli/node_modules/d3-ng2-service/src/bundle-d3"'.

如您所见,我使用d3-ng2-service将d3加载到我的应用中。有人能让我解开吗?干杯!

0 个答案:

没有答案
相关问题