Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
View does not get updated on Mobile app after angular variables are updated, though it works on browser

When the angular variables are updated inside the component after some API calls, it should be reflected in the UI of the mobile view (depending on the value of *ngIf), but it does not. It works on the web, desktop, etc. And if I create an extra button on the mobile page and click it OR reload the page, it works in mobile too. It seems like the mobile page requires initial interaction, to load the page correctly according to the variable change. It does not do the work itself.

<div *ngIf="!hasToken">
      <button type="button" class="btn btn-primary" (click)="Login()"><img src="images/icon-ms.ico">Login</button>
</div>

AngularComponent.ts

ngOnInit() {
 this.exampleService.getData(id).subscribe((result) => {
  if (result != undefined || result != null) {
  this.hasToken= true;
 }
}

Once the variable hasToken becomes true on ngOnInit(), it should hide the Login button, but it does not, though the value of the variable gets updated.

Any suggestion to solve this would be appreciated.

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

I believe that what you're experiencing is related to change detection. I suggest avoiding manually subscribing in the controller by using the async pipe. This improves the performance and works great with change detection.

You can do something like this:

readonly hasToken$ = this.exampleService.getData(id).pipe(map(result => !!result));
<div *ngIf="(hasToken$ | async) === false">
    <button type="button" class="btn btn-primary" (click)="Login()"><img src="images/icon-ms.ico">Login</button>
</div>
about 4 years ago · Santiago Gelvez Denunciar

0

I think the way you init/update your variable is incorrect. Can you add your .ts? You can also check ChangeDetectorRef.MarkForCheck() and ngOnchanges() but it's way too overkill for your problem.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda