1

Note this question is related to the one I asked here

In my html I am creating a overlay to a google map with

<agm-map ngDraggable [latitude]="latitude" [longitude]="longitude" [zoom]="zoom" *ngIf="locations" (mapReady)="mapReady($event)" >

Where mapReady is defined as

  mapReady($event: any) { 
    console.log("about fire init");
    nite.init($event);
    setInterval(nite.refresh(),10000);
  }

Now the problem is that nite.refresh() is supposed to fire every 10 seconds but it only fires one time. I'm not sure if this has something to do with my ngOnInit() which has a

timer(0, 10000).pipe(
      switchMap( _ => this.hawkerservice.fetchNews()
    )).pipe( map(...)).subscribe()

like function in it. Could this be causing the problem? The nite.init(...) is working fine i just need to be able to refresh the overlay without had refreshing the whole page which is what I am currently doing to get nite to refresh. Any thoughts? sorry if english is not the best.

Vladimir_314159
  • 1,457
  • 1
  • 9
  • 21
  • Just a quick note, when using `setInterval(nite.refresh(),10000);` you should be applying that to a component variable, and then using `ngOnDestroy() { ... }` to ensure it is removed when the component is destroyed. – Z. Bagley Jul 12 '18 at 15:57
  • Good point yes I need to do that thanks. – Vladimir_314159 Jul 12 '18 at 15:59

1 Answers1

0

I just discovered the answer which is I need to do

  mapReady($event: any) { 
    console.log("about fire init");
    nite.init($event);
    setInterval(function() { nite.refresh() }, 10000);
  }

In other words set Interval has to have a function() defined this way since nite is a js function not typescript.

Vladimir_314159
  • 1,457
  • 1
  • 9
  • 21