我在Ionic2项目中以页面的typescript编写的组件具有以下结构:
import { Component, ViewChild, ElementRef } from '@angular/core';
...
declare var google;
@Component({
selector: 'page-search',
templateUrl: 'search.html'
})
export class SearchPage {
@ViewChild('map') mapElement: ElementRef;
map: any;
guideList: Array<Guide>;
text: any;
lat : any;
lon : any;
constructor(public navCtrl: NavController, public recoshService: Recosh, public alertCtrl: AlertController) {
...
}
ngOnInit(){
this.loadMap();
}
loadGuides() {
...
}
setLat(l){
this.recoshService.setLat(l);
this.lat = l;
}
setLon(l){
this.recoshService.setLon(l);
this.lon = l;
}
setPos(lat, lon){
this.setLon(lon);
this.setLat(lat);
this.loadGuides();
}
loadMap(){
...
let marker = …Run Code Online (Sandbox Code Playgroud)