Reputation: 55
I am using Angular 2. Using basic google maps, all works fine ,now i want to call my custom function from
google.maps.event.addListener(map123,'click' ,(event)=> {
let id=123;
var lat=event.latLng.lat();
var lng=event.latLng.lng();
var marker = new google.maps.Marker({
position: new google.maps.LatLng(parseFloat(lat),parseFloat(lng)),
map: map123
});
this.serverinteraction(this.id_actual,this.lat_actual,this.lng_actual);
});
My custom function is in same typescript file:
serverinteraction(id , lat, lng)
{
}
Error: _this.serverinteraction is not a function.
How Can i call my custom function inside that event.
Upvotes: 1
Views: 628
Reputation: 115
This should work
var that = this;
google.maps.event.addListener(map123,'click' ,(event)=>
{
let id=123;
var lat=event.latLng.lat();
var lng=event.latLng.lng();
var marker = new google.maps.Marker({
position: new google.maps.LatLng(parseFloat(lat),parseFloat(lng)),
map: map123
});
that.serverinteraction(this.id_actual,this.lat_actual,this.lng_actual);
});
Upvotes: 1