A
A
Andrey Astafiev2018-02-14 09:26:52
JavaScript
Andrey Astafiev, 2018-02-14 09:26:52

How to connect and use yandex maps in angular?

The project is based on Angular, you need to use yandex maps on it. Packages with npm are not suitable, I need to work with regions and clusters and other things that the yandex maps api gives.
here is an example of how I connect and try to use
in the index.html file I load their library

<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>

here is my component
import {Component, OnInit} from "@angular/core";

declare var ymaps:any;

@Component({
  selector:'app-map',
  templateUrl:'./map.component.html'
})
export class MapComponent implements OnInit{
  public map :any;

  ngOnInit(){
    this.map = new ymaps.Map("map", {
      center: [55.76, 37.64],
      zoom: 7
    });
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Stroykin, 2018-02-18
@Astafiev_Andrey

ngOnInit() {
    ymaps.ready().then(() => {
      this.map = new ymaps.Map('map', {
        center: [50.450100, 30.523400],
        zoom: 12
      });
    });
  }

I
Ivan Sushkov, 2018-02-14
@jamesgoodwin

The logic of working with Yandex.maps in Angular "without a component" is exactly the same as working with Yandex.maps "without Angular" (in plain html).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question