question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

changeDetection Not checking for update when i use rxjs interval with ApplicationRef.isStable

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Don’t know whether it is worked in previous or not

Description

A clear and concise description of the problem...

If i want to use interval in my application i have to start interval after app isStable. But it makes application not to check for changes

πŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-if8xoz

In above link app.component.ts - ngOnInit hook my interval is running and console log give the correct value but the ui is not updating. This occurs only when i use ApplicationRef.isStable

πŸ”₯ Exception or Error





🌍 Your Environment

Angular Version:




Angular CLI: 7.0.7
Node: 10.10.0
OS: win32 x64
Angular: 7.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.7
@angular-devkit/build-angular     0.10.7
@angular-devkit/build-optimizer   0.10.7
@angular-devkit/build-webpack     0.10.7
@angular-devkit/core              7.0.7
@angular-devkit/schematics        7.0.7
@angular/cli                      7.0.7
@angular/fire                     5.1.1
@angular/pwa                      0.10.7
@ngtools/webpack                  7.0.7
@schematics/angular               7.0.7
@schematics/update                0.10.7
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.19.1

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Dec 20, 2018

@gkalpak, thanks for the update, and I believe isStable is outsideOf ngZone to avoid endless loop. So isStable next -> ngZone.run -> isStable next ....

1reaction
gkalpakcommented, Dec 19, 2018

I might do something like below (but I am neither a Zone.js nor an RxJS expert 😁):

const isStable$ = this.appRef.isStable.pipe(first(x => x));
const interval$ = interval(1000).pipe(startWith(null));
 
return new Observable(observer =>
  isStable$.subscribe(() =>
    this.zone.run(() => {
      let count = 0;
      return interval$.pipe(map(() => count++)).subscribe(observer);
    })));
Read more comments on GitHub >

github_iconTop Results From Across the Web

ApplicationRef - Angular
Returns an Observable that indicates when the application is stable or unstable. ... using RxJS interval ), and at the same time subscribe...
Read more >
How can I use 'interval' Rxjs function without executing ...
when you want to update the value you can Inject ChangeDetectorRef in the constructor and call the method this.changeDetectorRef.markForCheck();Β ...
Read more >
Boosting performance of Angular applications with manual ...
Angular uses NgZone/Zone.js to know when to trigger UI update (change detection) when our app data state changes. It brilliantly utilized the events...
Read more >
The Last Guide For Angular Change Detection You'll Ever Need
Developer updates the data model, e.g. by updating a component binding; Angular detects the change; Change detection checks every component in the componentΒ ......
Read more >
angular/core/core.d.ts - UNPKG
318, * (here incrementing a counter, using RxJS `interval`), ... 368, * You'll have to manually trigger the change detection to update the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found