Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49250

Update view from Behaviersubject

$
0
0

@anna_liebt wrote:

Hello,
I’m back and maybe I have forgotten all. Okay my experience with rxjs is very, very low.

What I wanna do ist, that i calculate in a loop some time comsuming things, After each step I wanna update my view, for example ‘step {{value | async}} is done’ and update a mat progressbar. I made a stackblitz with a structur simalar to that I have at https://stackblitz.com/edit/angular-hello-async-pipe-input-ufib6h

@Component({
  selector: "my-app",
  template: `
    <p>count$: {{ count$ | async }}</p>
    
    <button (click)="doCount()">count</button>
  `
})
export class AppComponent {
  count$ = new BehaviorSubject<number>(0);
  count = 0;

  constructor() {
    
  }

  doCount() {
    for (let i = 0; i < 10; i++) {
      this.doImportant();

      this.count$.next(i);
      console.log(i);
    }
  }

  doImportant() {
    let n = 0;
    for (let i = 0; i < 500000000; i++) {
      n = n + 0;
    }
  }
}

It shows the first value and last value, but it does not count like 1, 2, 3, 4…

Thanks advance and best regards, anna-liebt

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49250

Trending Articles