how to declare a date attribute on angular2 model

This is a typescript question. There is not a date type in typescript. You can use Date to indicate a native javascript Date object, but this is just the typing of the field. Angular/TS won't do any magic for you to coerce your value into a Date object. If your data is coming from a JSON source, dates are usually just strings (JSON doesn't support date objects).


You can use moment.js for easier way.

import { Moment } from 'moment';

export class Book {
    id: number;
    author_one: string;
    author_two: string;
    author_three: string;
    title: string;
    subtitle: string;
    publisher: string;
    year: Moment;
    city: string;
    edition: number;
    volume: number;
    pages: number;
    ISBN: string;
    barcode: string;
}