Z
Z
zlodiak2017-11-21 20:24:13
JavaScript
zlodiak, 2017-11-21 20:24:13

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>

This is what the component looks like:
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);

  };

}

Intuitively, I understand that communication is done through declare. But what is this command and how it works is not clear to me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kovalsky, 2017-11-21
@lazalu68

declare
any

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question