【发布时间】:2016-08-26 12:11:39
【问题描述】:
我想在信息窗口中添加一个按钮。如何在 Angular 2 中访问我的服务功能?
例子:
import {Injectable} from 'angular2/core';
@Injectable()
export class MapService {
private map: any;
constructor() { }
initialize(): void {
this.map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(33.751222, 33.98131),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
addMarker(): void {
let marker = new google.maps.Marker({
position: new google.maps.LatLng(33.751222, 33.98131),
map: this.map
});
let infoWindow = new google.maps.InfoWindow({
content: `<h6>Content</h6><button onclick="foo()">Click me</button>`
});
google.maps.event.addListener(marker, 'click', () => {
infoWindow.open(this.map, marker);
});
}
foo() {
console.log('Clicked!');
}
}
这个例子显然不起作用:“ReferenceError: foo is not defined”。我怎样才能使这个按钮起作用?
谢谢!
【问题讨论】:
标签: javascript google-maps google-maps-api-3 angular