将打字稿模块导入 angular 组件
Importing typescript module into angular component
我正在尝试在我的组件中使用某个库,但我似乎缺少正确包含它的步骤
我的组件如下。有问题的库是 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';
我正在尝试在我的组件中使用某个库,但我似乎缺少正确包含它的步骤
我的组件如下。有问题的库是 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';