传单地图未定义并同时初始化

Leaflet map is undefined and initialized at same time

我正在开发一个 Ionic 应用程序,该应用程序的其中一个页面是带有 Leaflet 地图部分的地点详细信息。

第一次进入地点详情页面时,地图工作正常,但返回并进入另一个地点详情页面时出现错误:

Error: "Map container is already initialized."

我已经添加了部分代码来关闭和删除地图但从未进入内部,因为始终未定义但当我尝试创建它时它告诉我它已初始化。

component.st:

ionViewWillEnter() {
  if (this.placeMapLeaflet) {
    this.placeMapLeaflet.off();
    this.placeMapLeaflet.remove();
  }
this.placeMapLeaflet = L.map("place_map_leaflet").setView([position.lat, position.lng], this.zoom);
}

问题是第二次 ALWAYS 未定义但已初始化。

有人可以帮助我吗?

已解决生命周期问题:

...
ionViewDidEnter() {
  this.placeMapLeaflet = L.map("place_map_leaflet").setView([position.lat, position.lng], this.zoom);
}

ionViewDidLeave() {
  this.placeMapLeaflet.off();
  this.placeMapLeaflet.remove();
}
...