I'm new to front-end development and Angular2.
I'm writing an app where I'm given a fromDate and an endDate, and the app needs to display the date range. For example, fromDate = '10/02/2016' endDate = '11/02/2016', the app will display the date range as: 10-11 Feb 2016, and this date range format may change in the future (also need to consider the cases where months or years are different of course).
My thought is to use chaining pipes: {{ dateArray | date: 'dd/MM/yyyy' | rangeDate}} where dateArray = [fromDate, endDate] and I hope {{ dateArray | date: 'dd/MM/yyyy'}} can return two formatted date strings (in an array) so I can then use my custom pipe I create:
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'dateRange'})
export class DateRangePipe implements PipeTransform {
transform(value: string[], args: any[]) {
return "desired output";
}
}
to easily manipulate with the two strings two get the desired output.
But this is wrong because Angular 2 Date Pipe cannot transfer more than one date value to string and it's return type is string, not string[].
So I was wondering if there is a way to write a for-loop-like thing in HTML to achieve this task. Like, it takes a date[], and send each of its item to the date pipe, and combine the results into a string[] and send it to dateRange pipe.