Sunday 19 August 2018

javascript - Scope variables in typescript

I'm working with Angular 2 (Typescript) on Ionic 2 App. I have one class NewFavoriteSitePage with private property siteForm and I can use this property in class methods but when I am inside one google maps method this variable is undefined. What are the scope of variable or How do I define the variable to access from both sides?



declare var google;
......
export class NewFavoriteSitePage {
.....
private siteForm: FormGroup;


loadMap(){
//I can access to siteForm here!
.....
google.maps.event.addListener(marker, 'dragend', function(marker, siteForm){
let newlatLng = marker.latLng;
console.log(this.siteForm); //Here this.siteForm is undefined
});
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...