In my ionic app, I want to display several maps in the same page. My code is given as below, but, when I run the script, I get an error as:
Uncaught TypeError: Cannot read property 'nativeElement' of undefined
at HomePage.webpackJsonp.982.HomePage.initMap
Can you tell me where is wrong in my code?
home.ts
maps: google.maps.Map[];
...
@ViewChild('map') mapElement;
...
initMap(i){
let latLng = new google.maps.LatLng(100, 100);
let mapOptions = {
center: latLng,
zoom:0,
scrollwheel: true,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
this.maps[i] = new google.maps.Map(this.mapElement.nativeElement,
mapOptions);
}
ionViewDidLoad() {
setTimeout(()=>{
for(var j=0;j<5;j++){
initMap(j);
}
}, 5000)
}
home.html
<ion-card class="transparent-card" *ngFor="let number of [0,1,2,3,4]" >
<div #map id="maps[number]" style="height:250px;"></div>
</ion-card>