Estoy usando https://preview.keenthemes.com/metronic8/demo1/
Estoy realizando la petición a un servidor, que me devuelve la respuesta en un Observable, ejecutar suscribe y dentro del observable modificar el valor de una variable no lo está tomando en el dom. Luego al dar click en alguna parte de la aplicación ya se actualiza la variable en el dom.
Ejemplo: tengo la variable title, que inicia el "Inicial", al ejecutar le método llamarApi(), le cambio el valor a "Cargando". Luego que el server responde al entrar al método next() actualizo las variables, pero no se reflejan en el dom.
Hi Jairo,
The issue you're experiencing might be related to the OnPush change detection strategy enabled in the demo1/src/app/app.component.ts file. This change detection strategy optimizes performance by only updating the DOM when there are changes to the component's inputs.
To resolve this issue, you can try disabling the OnPush change detection strategy in the AppComponent by removing or commenting out the following line:
changeDetection: ChangeDetectionStrategy.OnPush
Alternatively, you can manually trigger change detection using the ChangeDetectorRef service. Inject the ChangeDetectorRef into your component constructor and call the detectChanges() method after updating the variable in the next() method of the Observable.
import { ChangeDetectorRef } from '@angular/core';
// ...
constructor(private cdr: ChangeDetectorRef) {}
// ...
next(response: any) {
// Update your variables here
this.title = 'Loading';
// Manually trigger change detection
this.cdr.detectChanges();
}
By calling detectChanges(), Angular will reevaluate the component and update the DOM with the new variable values.
I hope this helps! Let me know if you have any further questions.