I am building a small angular 2 app for learning purposes and I plan to use datamaps for the map interface.
But there is no directive for this lib yet, so I am trying to hotwire it myself.
I've installed data maps
npm install datamaps
and I am using ng serve from angular-cli, but I can't make it work, I've tried importing it directly in the HTML ( just to see if it worked ) and it couldn't find the lib.
I get this from direct HTML import, even with the file in the correct location it is not send to the browser
datamaps.world.hires.min.js:1 Uncaught SyntaxError: Unexpected token <
I added it into my package.json and tried using it in my component, but also could not find it.
like this in my package.json
"datamaps": "^0.5.8"
What should be done for my html to see it if I am using it like this:
<!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>
Also what is the best way to import it into my component? I've seen that datamaps does not have a typings declared or a module from what I could find (I am using TS 2)
Here is my component so far
import {Component, OnInit, ViewChild} from '@angular/core'; import { Datamap } from '../../../node_modules/datamaps/dist/?????????????';
@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);
}
}
}