I use Yandex Maps API and Angular 6. When I launch the Angular CLI server, I always get the console out:
MapsComponent_Host.ngfactory.js? [sm]: 1
ERROR ReferenceError: ymaps is not defined at MapsComponent.push ../src / app / main-layout / main-layout / maps.component.ts.MapsComponent.ngOnInit (maps.component.ts: 19) at checkAndUpdateDirectiveInline (core.js : 9243) at checkAndUpdateNodeInline (core.js: 10507) at checkAndUpdateNode (core.js: 10469) at debugCheckAndUpdateNode (core.js: 11102) at debugCheckDirectivesFn (core.js: 11062) at ObjecteeeeezeeeezeeeezeeeezeeeezeeeezeeeezeeeezeeeezeeEezeeEezeeEeEeEeEeEeEeEeEeEeEeEeDeNeEndeNodeNodeInline (core.js: 10507) At checkAndUpdateNodeInline (core.js: 10507) At checkAndUpdateNode (core.js: 10469) ngfactory.js? [sm]: 1) at Object.debugUpdateDirectives [as updateDirectives] (core.js: 11054) at checkAndUpdateView (core.js: 10451) at callViewAction (core.js: 10692)
But after I go through the routing for example on the /login component and come back, the map suddenly appears.
My index.html:
<!doctype html> <html lang="en"> <head> ... </head> <body> </body> <script src="https://api-maps.yandex.ru/2.1/?apikey=...&lang=ru_RU"type="text/javascript"></script> ... </html> In maps.component.html there is:
<div id="map" style="width: 600px; height: 400px"></div> maps.component.ts contains:
import {Component, OnInit} from '@angular/core'; import {MainLayoutService} from '../main-layout.service'; declare var ymaps:any; @Component({ selector: 'app-dashboard', templateUrl: './maps.component.html' }) export class MapsComponent implements OnInit { properties: object; public map :any; constructor(private service: MainLayoutService) { } ngOnInit() { ymaps.ready().then(() => { this.map = new ymaps.Map('map', { center: [50.450100, 30.523400], zoom: 6 }); }); } }
head? although somehow you do not understand, do you have ascriptelement after badi? - overthesanity