wva*_*ner 4 typescript ngx-leaflet
我知道这是一个经常出现的问题,可以通过修复导入语句来解决。我目前有
import { LeafletModule } from 'node_modules/@asymmetrik/ngx-leaflet';
import * as L from 'leaflet';
import { } from '@types/leaflet';
Run Code Online (Sandbox Code Playgroud)
我正在引用选项,因此:
options = {
layers: [
this.googleHybrid
],
zoom: 1.49,
zoomSnap: 0,
center: L.latLng([180, -180])}
Run Code Online (Sandbox Code Playgroud)
我觉得我遇到了这个问题,因为将传单中的所有内容都导入为 L。有什么想法吗?
编辑:我还应该补充一点,这只是在测试中出现。
当 Angular.io 没有将 LeafletModule 正确加载到您的应用程序中时,就会发生这种情况。通常,您会执行以下操作:
首先,导入LeafletModule到您的应用程序模块中:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
LeafletModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
然后,如果您在应用程序模块的子模块中使用 ngx-leaflet,则还需要将其导入到该子模块中:
import { NgModule } from '@angular/core';
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
@NgModule({
declarations: [
],
imports: [
LeafletModule
],
providers: []
})
export class MyModule { }
Run Code Online (Sandbox Code Playgroud)
有一个教程介绍了如何使用 Angular CLI 启动和运行,但它没有解决使用 ngx-leaflet 的应用程序模块的子模块的情况。
其他一些注意事项:
LeafletModule。大多数构建管道会自动取消引用包。@types/leaflet进口。如果需要,大多数构建管道将自动获取类型信息。import * as L from 'leaflet';您还可以根据需要导入特定项目,例如,import Map from {leaflet};| 归档时间: |
|
| 查看次数: |
5877 次 |
| 最近记录: |