4

I'm in the middle of making some test data to my views, before I make the API calls to the API application.

In a service in my angular 2 application, I have created a interface which looks like this:

export interface amendmentBookings {
    bookingNumber: string;
    outboundDate: Date;
    returnDate: Date;
    route: string;
    Passengers: string;    
    vehicleType: string;
}

I have also created an array which must consist of type to this interface. The code looks like this:

var bookings: amendmentBookings[] = [
    {
        bookingNumber: "123456789",
        outboundDate: 
        returnDate:
        route: "Dünkirchen - Dover",
        vehicleType: "Car 1.85m x 4.5m",
        Passengers: "1 adult and 1 child"
    },
]

How can I insert a date in my test data?

I have tried with the new Date() which you use in javascript, like this:

new Date("February 4, 2016 10:13:00");

But that does not work..

1 Answer 1

13

You can try in your browser's console that the following JS code works so it should work in TypeScript too:

 var bookings = [{
     bookingNumber: "123456789",
     outboundDate: new Date("February 4, 2016 10:13:00"),
     returnDate: new Date("February 4, 2016 10:13:00"),
     route: "Dünkirchen - Dover",
     vehicleType: "Car 1.85m x 4.5m",
     Passengers: "1 adult and 1 child"
}];

console.log(bookings)

Please add an error you get.

Sign up to request clarification or add additional context in comments.

1 Comment

Well.. I found the problem.. for some reason, it worked when I closed down Visual Studio Code and opened it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.