将typescript模块导入角度组件

时间:2017-11-17 16:03:49

标签: angular npm node-modules angular5

我正在尝试在我的组件中使用某个库,但我似乎错过了正确包含它的步骤

我的组件如下。有问题的库是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没有定义。

1 个答案:

答案 0 :(得分:0)

使用此语法导入以这种方式构建的模块:

import * as geolib from 'geolib';