1

我按照主 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版本有关?

4

1 回答 1

1

确保将 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
]
...
于 2018-03-01T22:51:36.807 回答