Variable is not saved in Ionic 3

0

When I want to save a variable data, it is saved and displayed in the console, but if I want to use it elsewhere, it tells me that this undefined and I do not know what to do.

Here is a fragment of that code:

public valoractual:number;
 google.maps.event.addListener(marker, 'click', (function(marker,i) {
            return function() {
              this.valoractual=i;
              console.log(this.valoractual);//me la imprime aqui pero ni puedo usarla afuera
              infowindow.setContent(locationtemp[i]);
              infowindow.open(this.map, marker);
            }
          })(marker,i));

This only happens to me when I try to do it inside a bookmark and I do not know how to fix it.

    
asked by Carlos Escalante 02.09.2018 в 02:03
source

1 answer

0

Your question is ambiguous and lacks details, I would say that the problem is that you put an anonymous function inside another and you do not return the result to the corresponding context, try this way.

google.maps.event.addListener(marker, 'click', (marker, i) => {
  this.valoractual = i;
  console.log(this.valoractual);
  infowindow.setContent(locationtemp[i]);
  infowindow.open(this.map, marker);
});
    
answered by 26.09.2018 в 01:09