Sunday, August 19, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...