Я новичок в angular и пытаюсь создать простое приложение для карт Google.
Я продолжаю получать эту ошибку error TS2339: Property 'map' does not exist on type 'AppComponent'
Я пытаюсь получить доступ к атрибуту карты, но не могу. Может я не правильно инициализировал?
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
title = 'simple-gmaps-demo';
lat = 51.678418;
lng = 7.809007;
onMapReady(map: google.maps.Map) {
this.map = map;
this.map.setCenter({lat:-32, lng:127});
this.map.setZoom(10);
// this.map.data.loadGeoJson('http://localhost:4200/assets/sample-farms.geojson', {}, features => {
// console.info(features);
// });
}
}
Вам нужно объявить карту свойств
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
title = 'simple-gmaps-demo';
lat = 51.678418;
lng = 7.809007;
map: any; // add this line
onMapReady(map: google.maps.Map) {
this.map = map;
this.map.setCenter({lat:-32, lng:127});
this.map.setZoom(10);
// this.map.data.loadGeoJson('http://localhost:4200/assets/sample-farms.geojson', {}, features => {
// console.info(features);
// });
}
}
Объявите свойство карты в AppComponent под заголовком, например: -
map: google.maps.Map;
Большое спасибо за помощь, это решило мою проблему