首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带外部库的Angular 2延迟加载模块

带外部库的Angular 2延迟加载模块
EN

Stack Overflow用户
提问于 2017-10-31 21:08:48
回答 1查看 231关注 0票数 0

如何在延迟加载模块瞬间加载外部库(例如ngx-leaflet) (通过点击相应的按钮)?

我喜欢这样:

app.routing.ts

代码语言:javascript
复制
const appRoutes: Routes = [{
    path: 'gis',
    loadChildren: 'app/gis/gis.module#GisModule',
    canActivate: [AuthGuard]
}];

gis.module.ts

代码语言:javascript
复制
import { ModuleWithProviders, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

// components
import { GisControllerComponent } from './controller/gis.controller.component';

// modules
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { LeafletMarkerClusterModule } from '@asymmetrik/ngx-leaflet-markercluster';
import { LeafletDrawModule } from '@asymmetrik/ngx-leaflet-draw';

// routing
import { routing } from './gis.routing';

@NgModule({
  imports: [
    CommonModule,
    routing,
    LeafletModule.forRoot(),
    LeafletDrawModule.forRoot(),
    LeafletMarkerClusterModule
  ],
  declarations: [GisControllerComponent],
  exports: [GisControllerComponent]
})

export class GisModule {}

gis.controller.component.html

代码语言:javascript
复制
<div #MapContainer id="MapContainer">
  <div leaflet id="LeafletMap"
       leafletDraw
       [leafletOptions]="options"
       [leafletDrawOptions]="drawOptions"
       (leafletMarkerClusterReady)="markerClusterReady($event)"
       (leafletMapReady)="onMapReady($event)">
  </div>
</div>

但是当我使用这样的结构时,我得到的错误是我不能使用任何leaflet指令。但是,如果我在app.module.ts中添加导入小叶库,它可以正常工作,并且没有错误。

我只需要在加载模块时刻加载库。我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2017-11-02 00:10:42

我自己发现了一个错误。我在另外两个组件中使用了leaflet指令,它导致了这个错误。感谢您的参与!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47036282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档