Answer the question
In order to leave comments, you need to log in
How does declare connect google maps?
Please help me understand the meaning of the declare command in angular.
I have connected google maps to the angular framework. I connected directly, that is, without the use of modules and other ready-made solutions. At the same time, I used some kind of tutorial on YouTube. It's ok, the card is working.
The problem is that I would like to get into the details. Namely, how the framework sees the Google maps library, which I included in index.html (and therefore outside the framework's root tag):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gmap1</title>
<base href="/">
<script src="https://maps.googleapis.com/maps/api/js?key=blabla" async defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
import { Component, OnInit } from '@angular/core';
declare var google: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
private map: any;
ngOnInit() {
this.initMap();
}
private initMap(): void {
let mapEl = document.getElementById('map');
let mapOptions = {
center: new google.maps.LatLng(51, 7),
zoom: 8
};
this.map = new google.maps.Map(mapEl, mapOptions);
};
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question