我用这个种子开始使用Angular 2 Typescript和Webpack:https://github.com/haoliangyu/angular2-leaflet-starter.
我是大多数使用过的工具和技术的新手(Angular 2,Typescript,Webpack).虽然我越来越了解这些,但似乎我还没有掌握如何包含第三方非类型的JS库:
我想将leaflet-routing-machine.js包含到我的项目中.据我所知,虽然确实存在传单的类型,但是传单路由机并不存在.
我安装了包,npm install并添加了所需的快速启动代码,以显示路径.
map.service.ts
/// <reference path="../../typings/leaflet/leaflet.d.ts"/>
import {Injectable} from 'angular2/core';
import {Map} from 'leaflet';
Injectable()
export class MapService {
map: Map; // holds reference to the normal leaflet map object
showRoute(){
L.Routing.control({
waypoints: [
L.latLng(47.569198, 7.5874886),
L.latLng(47.5685418, 7.5886755)
]
}).addTo(this.map);
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的错误npm start是:
ERROR in ./app/services/map.service.ts
(56,11): error TS2339: Property 'Routing' does not exist on type 'typeof L'.
Run Code Online (Sandbox Code Playgroud)
据我了解,我不应该在index.html中包含JS文件,因为这应该由webpack自动完成.接下来的事实,我通常不知道该如何包括但分型(答案像第三方库 …