Automatic refresh of angular data update template

I have an array passed from the background

the data in the array is constantly changing

I want to refresh automatically when the contents of the array change without reorganizing the page template block

how can this be achieved?

Mar.25,2022
The

array is a reference variable, and if no impure pipe,angular is added to it, it will only detect whether the address of the variable has changed each time it is detected. That is to say, even if the content changes, but the memory address of the variable does not change, angular will not think that the variable has changed, so the page will not be refreshed. You can use async pipe. Or set the array variable to null, and then reassign it each time the array content is updated. But the second method is not very rigorous and should be used with caution.


Asynchronous operation may not trigger the check mechanism of angular. At this point, you can try to manually remind angular to re-render the view

  import { NgZone } from '@angular/core';
  constructor(public _ngZone:NgZone) {}

  public refresh() {
    this._ngZone.run(() => {});
  }

Menu