Angular 7: ChangeDetectorRef detectChanges() causes infinite loop when called from inside a subscription

前端 未结 1 1553
甜味超标
甜味超标 2021-01-24 00:59

I am posting here after reading all the material related to change detection and similar post and failing to solve my problem.

ChangeDetectorRef detectChanges()

相关标签:
1条回答
  • 2021-01-24 02:04

    I resolved this. Issue was not with the lifecycle but with a directive leaflet from ngx-leaflet project.

    When I removed leaflet related directive and bindings all errors vanished.

    Error came even with this as well:

    <ng-container *ngIf="!loading">
        <div
          class="map"
          leaflet
          (leafletMapReady)="onMapReady($event)"
          [leafletOptions]="options"
          [leafletLayers]="layers"
          [leafletLayersControl]="layersControl">
        </div>
    </ng-container>
    

    I tried adding detectChanges and markForCheck alternatively, but again got no luck.

      onMapReady(map: Map) {
        this.map = map;
        setTimeout(() => map.invalidateSize(), 1000);
        this.route.params.subscribe(params => {
          this.userId = params["userId"];
          this.loadActivity();
        });
        this.cdRef.markForCheck();
      }
    

    Finally, I ditched leaflet while writing this answer, and I am going to try Angular-Google-Maps.

    And yeah A-G-M is working fine.

    0 讨论(0)
提交回复
热议问题