【发布时间】:2016-10-23 03:26:50
【问题描述】:
谁能帮帮我。我使用 Microsoft Visual Studio 2015 在 TypeScripts 中创建了一个简单的项目,我从 git 存储库中添加了 2 个库“toastr”和“jquery”:https://github.com/DefinitelyTyped/DefinitelyTyped。添加后,Visual Studio 不会显示任何错误或警告(如图片中的 Visual Studio Screen )。但是当我运行应用程序时,这是我收到的:Uncaught ReferenceError: toastr is not defined。
... 和 index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="app.js"></script>
</head>
<body>
<h1>TypeScript HTML App</h1>
<div id="content"></div>
</body>
</html>
app.ts:
/// <reference path="toastr.d.ts" />
class Greeter {
element: HTMLElement;
span: HTMLElement;
timerToken: number;
constructor(element: HTMLElement) {
this.element = element;
this.element.innerHTML += "The time is: ";
this.span = document.createElement('span');
this.element.appendChild(this.span);
this.span.innerText = new Date().toUTCString();
}
start() {
this.timerToken = setInterval(() => this.span.innerHTML = new Date().toUTCString(), 500);
}
stop() {
clearTimeout(this.timerToken);
}
}
window.onload = () => {
var el = document.getElementById('content');
var greeter = new Greeter(el);
greeter.start();
toastr.info("ASDFGH");
};
【问题讨论】:
标签: git visual-studio typescript visual-studio-2015 typescript1.6