Angular 6 - Rendering problems if BrowserAnimationsModule imported (Openlayers)

前端 未结 2 545
醉梦人生
醉梦人生 2020-12-21 22:23

I basically have a App which renders a small map. On this page is also a \"toggle\" button which hides the small map with a *ngIf in the parent component and displays the ma

2条回答
  •  半阙折子戏
    2020-12-21 22:34

    You have to use ngAfterViewInit, then you can be 'sure' the element inside your components template is present in the DOM.

    ngAfterViewInit() {
      this.map = new OlMap({
        target: 'map',
        layers: [new OlTileLayer({ source: new OlOSM() })],
        view: new OlView({ zoom: 13, center: fromLonLat([13.376935, 52.516181]) }),
        controls: []
      });
    }
    

提交回复
热议问题