如何在Angular4中使用svg-pan-zoom库?

时间:2017-09-27 19:37:15

标签: angular svgpanzoom

 window.onload = function() {
  svgPanZoom('#demo-tiger', {
    zoomEnabled: true,
    controlIconsEnabled: true
  });
};

以上代码不适用于Angular ??

1 个答案:

答案 0 :(得分:3)

我使用过svg-pan-zoom 3.5.x版,以下代码片段可以帮助您导入库。

    // Psuedo angular TS code

    import * as SvgPanZoom from 'svg-pan-zoom';

    @Component({
      selector: 'app-svg-container',
      templateUrl: './svg-container.component.html',
      styleUrls: ['./svg-container.component.scss']
    })
    export class SvgContainerComponent implements OnInit, AfterViewInit {

      constructor() { }

      ngOnInit() {  }

      ngAfterViewInit() {
        // initializing the function
        let svgPanZoom: SvgPanZoom.Instance = SvgPanZoom('#wolrd-map-svg', this.options);
     /* see typing definiton for more APIs. */

      }

        ... More Codes...

    }