In some class in constructor I have method that is attached to click event listener.
this.mapButton.addEventListener('click', this.expandOrCollapseMap.bind(this));
The responsibility of that method is to download map and expand it on the view.
expandOrCollapseMap(eventArgs) {
// eventArgs.currentTarget != null
loadGoogleMapsApi({
key: '{{GOOGLE_MAPS.API_KEY}}',
}).then((googleMaps)=>{
if(!this.map) {
this.mapAPI = googleMaps;
this.map = new googleMaps.Map(this.mapContainer, {
zoom: 12,
center: {
lat: 40.722216,
lng: -73.987501
},
scrollwheel: false
});
}
}).then(()=>{
// eventArgs.currentTarget is null
let clickedButton = eventArgs.currentTarget;
this.changeMapIcon(clickedButton);
this.changeMapHeight();
this.addMarkersToMap(this.restaurants);
this.expanded = !this.expanded;
})
.catch((err)=>{
this.map = null;
console.log("Error while loading map: ", err);
});
}
My question is why when I debug in Chrome outside promise then I can access eventArgs.currentTarget
, while inside then callback eventArgs.currentTarget
is null, but other properties of eventArgs
can be accessed?