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.

Change Detection runs all time even if map is not present

See original GitHub issue

The issue is than if you have <agm-map> in component with *ngIf on it, the change detection runs every second after it is shown.

Steps to reproduce and a minimal demo of the problem

I created repo for reproduction.

What steps should we try in your demo to see the problem?

  1. Clone the repo.
  2. Put your API_KEY to app.module.ts.
  3. Run with ng serve
  4. Open the console window.
  5. Click on Show/Hide button - Map hides and change detection runs only couple of times and then stops
  6. Click on Show/Hide button again - Map is shown and in console the change detection logs keep running / there is also so much change detection running if you hover over

angular2 & angular-google-maps version

"@agm/core": "1.0.0-beta.0"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

4reactions
ByrelMitchellcommented, Dec 11, 2018

@SebastianM

I believe I tracked down where this issue is coming from. In the constructor for FitBoundsService, there’s an observable pipeline definition which basically samples the includeInBounds$ observable based on a variable timer, and then maps that onto a generation of the bounds.

The first problem is the internal timer is triggering angular change tracking every time it fires (by default, 5 times per second) regardless of whether the observable it’s sampling has a new value.

The second is that the FitBoundsService is not disposed on map-hide, but a new instance is created the next time the map is shown. This leak leads to very bad performance if change checking is remotely expensive.

I’m fairly new the RxJS and the Angular change-tracking system, so I’m not at all sure what the appropriate fix is here. Hopefully finding the problem will make this easy for someone more skilled than me.

2reactions
JiriBalcarcommented, May 28, 2017

Any update on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Detection runs all time even if map is not present #1019
The issue is than if you have <agm-map> in component with *ngIf on it, the change detection runs every second after it is...
Read more >
Angular Change Detection - How Does It Really Work?
Change detection works by detecting common browser events like mouse clicks, HTTP requests, and other types of events, and deciding if the view ......
Read more >
The Last Guide For Angular Change Detection You'll Ever Need
It will run change detection on marked components even though they are using the OnPush strategy.
Read more >
typescript - Run Angular change detection only once and stop ...
So i have many *ngIf in a single html template but i need to check *ngIf condition only once when the template is...
Read more >
Angular Change Detection | InfiniSwiss Blog
Change Detection can be defined as the process of identifying differences in the state of an object by observing it at different times....
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