Файл multi-date-picker.html очень похож на диапазон DatePicker ng-bootstrap
<!-- we not use (select)="onDateSelection($event)"-->
<ngb-datepicker #dp [displayMonths]="2" [dayTemplate]="t">
</ngb-datepicker>
<ng-template #t let-date="date" let-focused="focused">
<!--we use (click) event pass the event and the date-->
<span class="custom-day" (click)="onDateSelection($event,date)"
[class.focused]="focused"
[class.range]="isFrom(date) || isTo(date) || isInside(date) ||
isHovered(date)"
[class.faded]="isHovered(date) || isInside(date)"
<!--add a class.selected if the date belong to our dates selected -->
[class.selected]="isDateSelected(date)"
(mouseenter)="hoveredDate = date"
(mouseleave)="hoveredDate = null">
{{ date.day }}
</span>
</ng-template>
добавить функции isDateSelected (), addRangeDate () и addDate ().
//return true if is selected
isDateSelected(date:NgbDateStruct)
{
return (this.datesSelected.findIndex(f=>f.day==date.day && f.month==date.month && f.year==date.year)>=0);
}
addRangeDate(fromDate:NgbDateStruct,toDate:NgbDateStruct)
{
//We get the getTime() of the dates from and to
let from=new Date(fromDate.year+"-"+fromDate.month+"-"+fromDate.day).getTime();
let to=new Date(toDate.year+"-"+toDate.month+"-"+toDate.day).getTime();
for (let time=from;time<=to;time+=(24*60*60*1000)) //add one day
{
let date=new Date(time);
//javascript getMonth give 0 to January, 1, to February...
this.addDate({year:date.getFullYear(),month:date.getMonth()+1,day:date.getDate()});
}
this.datesSelectedChange.emit(this.datesSelected);
}
addDate(date:NgbDateStruct)
{
let index=this.datesSelected.findIndex(f=>f.day==date.day && f.month==date.month && f.year==date.year);
if (index>=0) //If exist, remove the date
this.datesSelected.splice(index,1);
else //a simple push
this.datesSelected.push(date);
}
для использования, просто:
<ngb-multi-date-picker [datesSelected]="datesSelected"
(datesSelectedChange)="change($event)"></ngb-multi-date-picker>
и
export class AppComponent
{
datesSelected:NgbDateStruct[]=[];
change(value:NgbDateStruct[])
{
this.datesSelected=value;
}
это Ссылка окончательный код.