Currently, in my Angular 2 app, I am utilizing the ng2-daterangepicker module. The module returns an object, but I require the date to be in YYYY-MM-DD format.
Although a date pipe could potentially solve this issue, it seems not possible to use it with the module as it doesn't involve a regular variable in the HTML. Despite having settings within the module to define the format, it appears to be ineffective and still outputs an object.
The .format method is unavailable due to Angular 2 being in typescript. After attempting .toString(), I managed to get a date in this format: Wed Mar 08 2017 00:00:00 GMT+0100 - however, I'm unsure about how to convert that into the required format.
HTML
<input type="text" name="daterangeInput" daterangepicker [options]="options" (selected)="selectedDate($event)"/>
TYPESCRIPT
startDate: any;
endDate: any;
private selectedDate(value: any) {
this.startDate = value.start.toString();
console.log(this.startDate);
this.endDate = value.end.toString();
console.log(this.endDate)
// console.log(value.end.format("YYYY-MM-DD"));
}
constructor(
private mapsAPILoader: MapsAPILoader,
private ngZone: NgZone,
private http: Http,
private daterangepickerOptions: DaterangepickerConfig
) {
this.daterangepickerOptions.settings = {
locale: { format: 'YYYY/MM/DD' },
alwaysShowCalendars: false
};
}
I am relatively new to Angular 2, so any assistance would be greatly appreciated!