I have a div in my code named #map that will be displayed after a certain condition is met in a for loop.
<div *ngFor="let message of fullMessagesArr">
<div *ngIf="message.replyMap">
<div #gmap style="width:100px;height:400px"></div>
</div>
</div>
Below is my .ts file with the initMap
function.
@ViewChild('gmap') gmapElement: ElementRef;
map: google.maps.Map;
initGMap = () => {
const mapProp = {
center: new google.maps.LatLng(6.9404, 79.8464),
zoom: 15,
mapTypeId: google.maps.MapTypeId.satellite
};
this.map = new google.maps.Map(this.gmapElement.nativeElement, mapProp);
}
The initGMap
function is called within the sendMessage
function.