Mandersen
Mandersen

Reputation: 805

Date in typescript in my angular 2 application

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..

Upvotes: 4

Views: 50699

Answers (1)

MartyIX
MartyIX

Reputation: 28648

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.

Upvotes: 13

Related Questions