如何在Angular 2中使用amcharts的ammaps?

3

我希望在 Angular 2 应用程序中使用 ammaps。从代码来看,很明显我的组件不知道这个库。
这是我的文件的样子:
map.component.html

<script src="http://www.ammap.com/lib/ammap.js" type="text/javascript">   </script>
<script src="http://www.ammap.com/lib/maps/js/worldLow.js"  type="text/javascript"></script>


<div id="mapdiv" style="width: 600px; height: 400px;"></div>

map.component.ts

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

//saw this on another SO article so that 
//typescript does not shout for type not defined

declare var AmCharts: any;

@Component({
selector: 'newsmap-map',
templateUrl: 'app/views/map.component.html',
directives: [],
styleUrls: ['app/css/map.component.css']
})

export class MapComponent { 

AmCharts: any;
//using ngOnint to call the required 
//javascript that I've pulling in the html file
ngOnInit(){
     this.AmCharts = new AmCharts({
        makeChart( "mapdiv", {

          "type": "map",


          "dataProvider": {
            "map": "worldLow",
            "getAreasFromMap": true
          },


          "areasSettings": {
            "autoZoom": true,
            "selectedColor": "#CC0000"
          },


          "smallMap": {}
        } )

    }
}

如何让这个起作用呢? 这是我ammaps的指南

谢谢!

1个回答

0

在Angular 2模板中无法使用脚本标记,但您可以将非Angular代码放入index HTML中来实现。

如果您想在Angular 2中使用代码,需要使用Ststem.js导入并加载。您只需要在npm上找到一个可用的AmCharts库即可。

请参考: Angular 2和AmCharts

作为日后参考,请在发布问题之前先使用搜索引擎进行查询。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接