I'm using angular 11.0.1 and Ionic 5.4.16 and trying to get Google map. I have put API key and used following commands
map.page.html
<div #mapElement class="map">
map.page.ts
import { Component, OnInit, ViewChild } from '@angular/core';
declare var google;
@Component({
selector: 'app-map',
templateUrl: './map.page.html',
styleUrls: ['./map.page.scss'],
})
export class MapPage implements OnInit {
map;
@ViewChild('mapElement') mapElement;
onstructor() {
}
ngOnInit() {
}
ngAfterContentInit() : void
{
this.map = new google.maps.Map (
this.mapElement.nativeElement,
{
center: {lat: -34.397, lng: 150.644},
zoom: 8
}
);
}
}
and I'm getting following error.
TypeError: Cannot read property 'nativeElement' of undefined