0

My problem is that I want to use my Appointment class in my app.ts file.

I reference it in my app.ts on the top:

/// <reference path="Appointment.ts"/>

Then I instantiate it and print the clientID:

var app : Appointment = new Appointment(1, 2, "User", 3);;

console.log(app.ClientID);

But then I get ReferenceError: Appointment is not defined

I also added the .js script of Appointment to my html file.

My Appointment looks like this:

class Appointment {
    // some properties

    constructor(clientID: number, state: number, userCreated: string, activityID: number) {
        // constructor
    }
}
5
  • Check the generated js file to see if the Appointment class was compiled into javascript. If it wasn't check for compilation errors in your class. Commented Jul 15, 2014 at 6:21
  • Yes it compiles to a Appointment.js file. Commented Jul 15, 2014 at 6:26
  • Try to write this code in the Appointment.ts file. If it works, then as you said this should be a reference path problem(check the path). If not, then it's weird and I need some more info in order to help you.. Commented Jul 15, 2014 at 6:27
  • Is appointment.js loaded before App.js? Commented Jul 15, 2014 at 6:30
  • If I copy the Appointment in my app.ts file it works! So it's a reference error. How do I reference it correctly? Commented Jul 15, 2014 at 6:37

1 Answer 1

1

Your script references should look like this (order is important... and .js file extension is important too!)

<script src="Appointment.js"></script>
<script src="app.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Oh god. Can't believe I did it the wrong way! :D Thank you!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.