【发布时间】:2018-05-01 11:17:50
【问题描述】:
我正在尝试在我的组件中使用某个库,但我似乎缺少正确包含它的步骤
我的组件如下。有问题的图书馆是 geolib
import { Component, OnInit } from '@angular/core';
import { StationsService } from '../../../services/stations/stations.service';
import { Station } from '../../../classes/station.model';
import 'geolib';
@Component({
selector: 'app-pollution',
templateUrl: './pollution.component.html',
styleUrls: ['./pollution.component.scss']
})
export class PollutionComponent implements OnInit {
private markers: Station[];
constructor(private stationsService: StationsService) { }
ngOnInit() {
this.stationsService.GetAll().subscribe(
res => {
for (let i of res) {
var t = geolib.computeDestinationPoint({ latitude: i.Lat, longitude: i.Long }, 1234, 90);
}
this.markers = res;
}
);
}
}
geloibs .d.ts 文件如下
declare namespace geolib {
.....
}
declare module "geolib" {
export = geolib;
}
工具没有抱怨,一切都编译了,但是当我运行它时,geolib 没有定义。
【问题讨论】:
-
你试过 import * as geolib from 'geolib';
-
成功了!谢谢!提交作为答案,我会这样标记。
-
完成,很高兴为您提供帮助
标签: angular npm node-modules angular5