Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(