2016-05-15 43 views
3

我想在角度2應用程序中使用ammaps。 查看代碼很明顯,我的組件不知道庫。
這是我的文件看起來像:
map.component.html如何在角度2中使用amcharts的ammaps?

<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": {} 
     }) 

    } 
} 

}

現在我怎麼做這項工作? 這是guide my ammaps

謝謝!

回答

0

腳本標記在Angular 2模板中不起作用,但是,您可以將非角度代碼放入索引HTML中並且它將起作用。

如果您想在Angular 2中使用代碼,您需要導入它並使用Ststem.js加載它。你只需要在npm上找到一個可用的AmCharts庫。

看看這個:Angular 2 and AmCharts

以供將來參考,您應該張貼問題之前,使用搜索引擎。