【发布时间】:2014-09-05 05:32:56
【问题描述】:
我的问题是我想在我的 app.ts 文件中使用我的 Appointment 类。
我在顶部的 app.ts 中引用了它:
/// <reference path="Appointment.ts"/>
然后我实例化它并打印clientID:
var app : Appointment = new Appointment(1, 2, "User", 3);;
console.log(app.ClientID);
然后我得到ReferenceError: Appointment is not defined
我还将 Appointment 的 .js 脚本添加到我的 html 文件中。
我的约会如下所示:
class Appointment {
// some properties
constructor(clientID: number, state: number, userCreated: string, activityID: number) {
// constructor
}
}
【问题讨论】:
-
查看生成的js文件,看Appointment类是否编译成javascript。如果不是检查你的类中的编译错误。
-
是的,它编译成 Appointment.js 文件。
-
尝试在 Appointment.ts 文件中编写此代码。如果可行,那么正如您所说,这应该是参考路径问题(检查路径)。如果没有,那就太奇怪了,我需要更多信息来帮助你..
-
app.js 之前是否加载了约会.js?
-
如果我将约会复制到我的 app.ts 文件中,它就可以工作!所以这是一个参考错误。如何正确引用?
标签: javascript html typescript