【发布时间】:2016-04-02 16:22:43
【问题描述】:
我正在尝试将 typescript 传单库导入到我的 angular 2 应用程序中。
这是我的地图组件。我已经使用 tsd install 安装了 leaflet.d.ts 并且我的应用程序没有抱怨 /// <reference path="../../typings/leaflet/leaflet.d.ts"/> 但是当我尝试使用作为 leaflet.d.ts 中的导出模块的 L.map 时,我收到错误“ReferenceError: L is没有定义的”。这是我第一次尝试在 angular 2 中导入外部打字稿库,显然我做错了什么。
/// <reference path="../../typings/leaflet/leaflet.d.ts"/>
import { Component } from 'angular2/core';
@Component({
selector: 'map',
template: `
<div id="map"></div>
`,
})
export class Map{
constructor(){
var map = new L.Map('map', {
zoomControl: false
});
}
package.json
{
"dependencies": {
"angular2": "^2.0.0-beta.3",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"normalize.css": "^3.0.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"systemjs": "0.19.6",
"typings": "^0.6.4",
"zone.js": "^0.5.11"
},
"devDependencies": {
"concurrently": "^1.0.0",
"gh-pages": "^0.11.0",
"grunt": "~0.4.5",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^1.0.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-sass": "~0.9.0",
"grunt-contrib-uglify": "~0.5.0",
"grunt-shell": "^1.2.1",
"lite-server": "^2.0.1",
"normalize.css": "^3.0.3",
"typescript": "^1.7.5"
},
"scripts": {
"publish": "node publish.js",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
}
}
tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"leaflet/leaflet.d.ts": {
"commit": "1da639a106527e0c4010b354a1efe52a3059a291"
}
}
}
谁能告诉我我做错了什么?
谢谢!
【问题讨论】:
-
我相信您还需要将leaflet.js 连接到您的页面。 d.ts 文件仅用于告诉 TypeScript 一些 JS 代码,d.ts 不导入实际代码。
-
好的。我的项目文件夹中有传单 js 文件。你知道我如何将我的 ts 文件连接到这个文件夹吗?
-
你可以只使用
标签: typescript angular tsd