为 angular 4 导入 Leaflet Draw NGX

Importing Leaflet Draw NGX for angular 4

我遵循了主要 git 中的步骤: https://github.com/Asymmetrik/ngx-leaflet

首先我安装了所需的库(leaflet、leaflet-draw、leaflet-ngx 和 leaflet-draw-ngx)

然后我在 app.module 中声明了所需的指令导入。

在我看来,我设置了以下内容:

<div class="col-md-6" style="height: 400px;"
         leaflet
         leafletDraw
         [leafletOptions]="options"
         [leafletLayers]="layers"
         [leafletLayersControl]="layersControl"
         [leafletDrawOptions]="drawOptions">
</div>

但出现以下错误:

> Uncaught Error: Template parse errors:
Can't bind to 'leafletDrawOptions' since it isn't a known property of 'div'. ("fletDraw [leafletOptions]="options" [leafletLayers]="layers" [leafletLayersControl]="layersControl" [ERROR ->][leafletDrawOptions]="drawOptions"> </div> <div class="col-md-6"> <table class="table table-striped c"): ng:///gxxxx.html@0:258
    at syntaxError (compiler.es5.js?524d:1689)
    at TemplateParser.parse (compiler.es5.js?524d:12802)
    at JitCompiler._compileTemplate (compiler.es5.js?524d:26852)
    at eval (compiler.es5.js?524d:26772)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.es5.js?524d:26772)
    at eval (compiler.es5.js?524d:26659)
    at Object.then (compiler.es5.js?524d:1679)
    at JitCompiler._compileModuleAndComponents (compiler.es5.js?524d:26658)
    at JitCompiler.compileModuleAsync

我是新手 angular 4,我是不是做错了什么?还是跟ES版本有关?

确保将 Leaflet 和 LeafletDraw 模块导入到定义组件的模块中(不仅仅是在 AppModule 中)。

在你的AppModule.ts中:

import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { LeafletDrawModule } from '@asymmetrik/ngx-leaflet-draw.module';
...
imports: [
    ...
    LeafletModule.forRoot(),
    LeafletDrawModule.forRoot()
]
...

在组件的模块中:

import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { LeafletDrawModule } from '@asymmetrik/ngx-leaflet-draw.module';
...
imports: [
    ...
    LeafletModule,
    LeafletDrawModule
]
...