I'm currently using Google Maps and I want to display the map only if a certain condition is true.
HTML:
<div *ngIf="anyboolToShowMapOrNot" #map id="map"></div>
Here's my TypeScript code:
@ViewChild("map",{static: true}) mapElement:ElementRef;
map: any;
constructor(private shareService: ShareService) { }
ngOnInit() {
}
ionViewWillEnter(){
this.initMap();
}
initMap(){
this.map = new google.maps.Map(this.mapElement.nativeElement,this.shareService.getMapOptions(google));
for(let i = 0; i < 10 ; i++){
this.addMarker(this.map,i,i,"jow sicha");
}
}
While the map functions properly without the ngIf, I encounter the following error when using ngIf:
Cannot read property 'nativeElement' of undefined