I have an Angular 2 component that is defined in the file comp.ts in this way like this:
import {Component} from \'angular2/core\';
@component({
selecto
I have found a solution. First of all, the following line:
must be inserted in the index.html file. The code which creates the map must be inserted in the comp.ts file. In particular, it must be inserted in a special method, namely "ngOnInit", which can be positioned after the constructor of the class. This is comp.ts:
import { Component } from 'angular2/core';
declare const google: any;
@Component({
selector: 'my-app',
templateUrl:'appHtml/app.html',
styleUrls: ['css/app.css']
})
export class AppMainComponent {
constructor() {}
ngOnInit() {
let mapProp = {
center: new google.maps.LatLng(51.508742, -0.120850),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
let map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
}
}
Finally, the div with id "googleMap", which is going to contain the google map, must be inserted in the comp.html file, which will look like this: