Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
ionic 4 - setting page variable not working in iOS and Android, but browser OK in browser

I'm using google maps and trying to show a div when the user clicks a pin.

<div *ngIf="this.viewing_place">
  {{ this.viewing_place?.title || 'NO_PLACE' }}
</div>

function redrawMap(){
  let self = this;
  this.places.forEach(function(place){
    let marker = self.map.addMarkerSync({ position :new LatLng(place.pin_lat, place.pin_long) });
    marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
      self.openPlaceInfo(place);
    });
  });
}

The click event is working good and the place object is being passed ok.

openPlaceInfo(place){
  console.log(place); //===========> shows correct object
  this.viewing_place = place; //======> set the page variable
}

The problem is that the div is not being displayed, like the variable this.viewing_place is not set.

So I created a manual method just for testing, and when I use this function, it works correctly.

manuallyTest(){
  this.viewing_place = {title:'test place'};
}

Am I doing something wrong? This happens only in iOS an Android.. It works perfectly in browser.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In mobile devices, angular has limitation calling change detection cycle when a variable updates from observable. I experienced this when I worked with Ionic. Try running you function inside NgZone to force the change detection cycle to re-render the UI.

constructor() {
  ...
  private zone: NgZone
}


marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
  this.zone.run(() => {
   self.openPlaceInfo(place);
  });
});

OR

openPlaceInfo(place){
  console.log(place); //===========> shows correct object
  this.zone.run(() => {
    this.viewing_place = place; //======> set the page variable
  });
}

Hope this helps you!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda