Sunday, September 22, 2019

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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...