我正在構建一個用於學習目的的小角度2應用程序,並且我打算將datamaps用於地圖界面。無法將數據映射庫導入到Angular 2應用程序的HTML中
但是這個庫還沒有指令,所以我正在嘗試自己的熱線。
我已經安裝了數據映射
NPM安裝的資料地圖
,我使用NG從角CLI發球局,但我不能讓它工作,我已經試過進口它直接在HTML中(只是爲了看看它是否工作),它無法找到該庫。
我得到這個從直接HTML進口,即使在正確的位置,該文件是不是發送到瀏覽器
datamaps.world.hires.min.js:1 Uncaught SyntaxError: Unexpected token <
我添加到我的package.json並在我的組件使用它嘗試,但也找不到它。
像這樣在我的package.json
"datamaps": "^0.5.8"
應該怎樣做對我的html看看吧,如果我使用它是這樣的:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>AskTheWorld</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"></script>
<script src="../node_modules/datamaps/dist/datamaps.world.hires.min.js"></script>
</head>
<body>
<app-geochart-component>Loading...</app-geochart-component>
<div id="container" style="position: relative; width: 500px; height: 500px;"></div>
<script>
var map = new Datamap({element: document.getElementById('container')});
</script>
</body>
</html>
還什麼是最好的方式將它導入我的組件?我見過的資料地圖沒有從我能找到聲明的分型或模塊(我使用TS 2)
這裏是我的組件至今
進口{組件,OnInit的,ViewChild}從'@角/芯'; 從'../../../ node_modules/datamaps/dist/????????????'導入{Datamap};
@Component({
selector: 'app-geochart-component',
templateUrl: './geochart-component.component.html',
styleUrls: ['./geochart-component.component.css']
})
export class GeochartComponentComponent implements OnInit {
@ViewChild('container') canvas;
constructor() { }
ngOnInit() {
var map = new Datamap(this.canvas);
}
}
}
不錯,謹慎講究還是指點我第二種方法的正確方向? –
我的意思是那裏有一個文件? –
我有一個鏈接到另一個stackoverflow帖子。今天晚些時候我回到家後我會把它給你。 –