Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

La plantilla demo1 de Metronic para angular, tiene un error al actualizar el DOM


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.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)

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.

Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(