I\'m working with Angular 2 and I have this code:
JS, this code initiates the employee-variable for the template:
handleEmployee(employee : Employee)
I think the accepted answer lacks a function call to transform input date string to Date object. So this:
(ngModelChange)="startDate = $event"
Should be something like:
(ngModelChange)="startDate = toDate($event)"
I'm using Moment.js, which makes things MUCH easier:
my.component.ts
...
import * as moment from 'moment';
...
@Component ({
...
})
export class MyComponent implements OnInit {
public fromDate: moment.Moment;
public toDate: moment.Moment;
ngOnInit() {
this.toDate = moment();
this.fromDate = moment().subtract(1, 'week');
}
dateStringToMoment(dateString: string): moment.Moment {
return moment(dateString);
}
my-component.html
...
...