I am using a subscription for Observable, and when it finishes I need it to call a function from this class. The issue is that the "this" keyword refers to the subscription and not to the class scope. Here is the code snippet:
export class GoogleMapComponent{
Position: object;
constructor(public MapFunctionsProvider: MapFunctionsProvider) {
let posObservable = this.MapFunctionsProvider.getPosition();
posObservable.subscribe(data =>{
this.Position = data;
this.createMap(); // "this" keyword refers to the subscription
});
function createMap(){
console.log('run');
}
}
}
How can I call createMap() without declaring a new variable for the "this" keyword?