On my EventCreate's TypeScript class, I have startDateTime and endDateTime properties with the datatype Date. HTML5 uses the input type time to get the time. I just want to ask: how do I make input type time work with TypeScript and Angular2?
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { EventCreate } from './eventCreate';
@Component({
selector: 'add-Event',
templateUrl: './event-add.component.html',
})
export class EventAddComponent {
title: string;
description: string;
locationId: number;
locationDetails: string;
categoryId: number;
isRegistrationRequired: boolean;
eventDate: Date;
startDateTime: Date;
endDateTime: Date;
maximumRegistrants: number;
newEvent: EventCreate;
constructor(private router: Router) { }
createNewEvent() {
console.log('new Event Created');
this.newEvent = new EventCreate(
this.title,
this.description,
this.locationId,
this.locationDetails,
this.categoryId,
this.isRegistrationRequired,
this.eventDate,
this.startDateTime,
this.endDateTime,
this.maximumRegistrants
);
console.log(this.newEvent);
//call service
//call route to go to Home page
this.router.navigate(['/home']);
}
cancel() {
this.router.navigate(['/home']);
}
}
export class EventCreate {
constructor(
public title: string,
public description: string,
public locationId: number,
public locationDetails: string,
public categoryId: number,
public isRegistrationRequired: boolean,
public eventDate: Date,
public startDateTime: Date,
public endDateTime: Date,
public maximumRegistrants: number,
) { }
}
<form>
<div class="form-group">
<label>Start Time:</label>
<input type="time" name="startDateTime" [(ngModel)]="startDateTime">
</div>
<div class="form-group">
<label>End Time:</label>
<input type="time" name="endDateTime" [(ngModel)]="endDateTime">
</div>
</form>
Stringto store the time? If in doubt, visit the documentation.public startDateTime: String;. You can see this by doing the following:console.log(typeof this.startDateTime);typeis a native attribute of<input>that can have many values including the stringtimeto denote an input of type "time". Can you provide more detail on what you mean by : "how to make it work with typescript and angular 2 "