导入Leaflet Draw NGX for angular 4

问题描述 投票:1回答:1

我按照主要的git:https://github.com/Asymmetrik/ngx-leaflet的步骤

首先我安装了所需的库(传单,传单,传单-ngx和传单-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

我是角色4的新手,我做错了什么?或者它与ES版本有关?

angular leaflet angular-directive ngx-leaflet
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
]
...
© www.soinside.com 2019 - 2024. All rights reserved.