[英]Import class from another file in TypeScript
My problem is that I want to use my Appointment class in my app.ts file. 我的问题是我想在我的app.ts文件中使用我的约会类。
I reference it in my app.ts on the top: 我在顶部的app.ts中引用了它:
/// <reference path="Appointment.ts"/>
Then I instantiate it and print the clientID: 然后我实例化它并打印clientID:
var app : Appointment = new Appointment(1, 2, "User", 3);;
console.log(app.ClientID);
But then I get ReferenceError: Appointment is not defined
但是然后我得到
ReferenceError: Appointment is not defined
I also added the .js script of Appointment to my html file. 我还将约会的.js脚本添加到了我的html文件中。
My Appointment looks like this: 我的约会如下:
class Appointment {
// some properties
constructor(clientID: number, state: number, userCreated: string, activityID: number) {
// constructor
}
}
Your script references should look like this (order is important... and .js
file extension is important too!) 您的脚本引用应如下所示(顺序很重要...
.js
文件扩展名也很重要!)
<script src="Appointment.js"></script>
<script src="app.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.