Date in typescript in angular 2 application

I am in the middle doing some test data for my views before making API calls to an API application.

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

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

I also created an array, which should consist of a type of this interface. The code is as follows:

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 tried using the new Date () you are using in javascript, for example:

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

But that does not work.

+4
source share
1 answer

You can try using the following JS code in your browser console so that it also works in TypeScript:

 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 the error you receive.

+12
source

Source: https://habr.com/ru/post/1627263/


All Articles