0

The title says it all : here is my code.

export class MapComponent {

@ViewChild(DirectionsMapDirective) vc:DirectionsMapDirective;

directionLst : any;


constructor() {
  this.directionLst = [];
}

mapClicked = function($event: MouseEvent) {
   [...] //hidden code not important
    this.vc.updateDirections().then(function(data) {
        this.directionLst = data;
    });  
}

Now if you look at the code inside "mapClicked" there I receive a promise after calling "updateDirections()" the data received is A1. The problem is that in the then function "this" points to null and if I only use "directionLst = data", I get direct is undefined. How can I access the variable from this function? Btw this is typescript of course.

MasterJohn
  • 439
  • 4
  • 17
  • Amazing, thanks I'm removing this one. – MasterJohn Nov 30 '16 at 02:19
  • Also note that with typescript when you declare a function with the fat-arrow '=>', 'this' is captured where the function is created rather than where it is invoked. So you can modify your function to be something like `mapClicked = () => {..}`. See https://www.typescriptlang.org/docs/handbook/functions.html#this – shusson Nov 30 '16 at 02:36

0 Answers0