/** * Created by hao on 16/4/14. */ import {Component, ElementRef, Input, OnInit} from '@angular/core'; const URL:string = 'http://webapi.amap.com/maps'; const ID:string = 'amap-container'; @Component({ selector: 'map', template: '' }) export class AMapComponent implements OnInit { @Input() version:string = '1.3'; @Input() key:string = ''; private map; constructor(private el:ElementRef) { el.nativeElement.id = ID; } ngOnInit() { let script = document.createElement('script'); script.type = 'text/javascript'; script.src = `${URL}?v=${this.version}&key=${this.key}`; script.onload = () => { this.map = new AMap.Map(ID); } document.body.appendChild(script); } }