'L'表示UMD全局 - 编译错误

Gré*_*EUT 13 typescript webpack angular-cli angular ngx-leaflet

我在我的项目中使用了插件ngx-leafletangular-cli.

我正在尝试使用文档中描述的传单,例如:

在此输入图像描述

问题是当我尝试编译时出现以下错误:

在此输入图像描述

编译:

ng serve --aot
Run Code Online (Sandbox Code Playgroud)

上下文:

在此输入图像描述


我确实尝试L使用以下方式导入:

import { LeafletModule } from '@asymmetrik/ngx-leaflet';

但我在文档和github中找不到任何东西.

我确实删除了模块atm进行编译,但我需要一个解决方法.

这是package.json我使用的:

在此输入图像描述


这是我的组件内部的代码,用户'L':

@Component({
  selector: 'app-map-screens-element',
  templateUrl: './map-screens-element.component.html',
  styleUrls: [
    './map-screens-element.component.scss',
  ],
})

export class MapScreensComponent implements OnInit {
  /**
   * setting map options
   */
  public $mapOptions = {
    // we use the layer openstreetmap
    layers: [
      L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
    ],
    zoom: 15,
    center: L.latLng([48.866667, 2.333333]),
  };
}
Run Code Online (Sandbox Code Playgroud)

这里将模块导入我的项目:

import { LeafletModule } from '@asymmetrik/ngx-leaflet';

@NgModule({
  imports: [
    LeafletModule,
  ],
  declarations: [
    // ...
  ],
  exports: [
    // ...
  ],
})

export class SharedElementModule { }
Run Code Online (Sandbox Code Playgroud)

小智 21

您缺少在组件顶部导入L.像这样:

import * as L from 'leaflet';
Run Code Online (Sandbox Code Playgroud)