the reason why google maps is not defined there, is because it is the callback of a function, which makes 'this' not equal to the page anymore, putting it in a variable will fix the issue.
private siteForm: FormGroup;
loadMap(){
var siteformFromPage=this.siteForm; //this should work
google.maps.event.addListener(marker, 'dragend', function(marker, siteForm){
let newlatLng = marker.latLng;
console.log(siteformFromPage);
});
}
EDIT: if you want the latest value, you could also try is this way:
private siteForm: FormGroup;
loadMap(){
var that=this; //cache that value of the page.
google.maps.event.addListener(marker, 'dragend', function(marker, siteForm){
let newlatLng = marker.latLng;
console.log(that.siteformFromPage);
});
}
No comments:
Post a Comment