首页 > 解决方案 > 在 datepicker 中添加 TODAY 和 TOMORROW 选项

问题描述

我需要在 ngx-bootstrap datepicker 中添加 TODAY 和 TOMORROW 选项。为此,我更改了以下bs-current-date-view.component.js代码node_modules/ngx-bootstrap/datepicker/themes/bs/bs-current-date-view.component.js

 BsCurrentDateViewComponent.decorators = [
    { type: Component, args: [{
        selector: 'bs-current-date',
        template: "<div class=\"current-timedate\"><button (click)=\"currentDate()\" class=\"active\">TODAY</button><button class=\"tomorrow\">TOMORROW</button></div>"
    },] },
];

但我无法为其添加功能,以从今天和明天的按钮中获取值。

以下是我到目前为止尝试过的代码

BsCurrentDateViewComponent.prototype.currentDate = function (en) {
    let today = new Date();
    let dateObj = {};
    dateObj.date = today;
    dateObj.isOtherMonth = false;
    dateObj.isDisabled = false;
    BsDatepickerContainerComponent.prototype.daySelectHandler(dateObj);
    alert();
};

BsDatepickerContainerComponent.prototype.daySelectHandler = function (day) 
{
    console.log(day);
    console.log(this._actions.select(day.date));
    this._store.dispatch(day);
};

日期选择器

标签: angulartypescriptdatepickerngx-bootstrap

解决方案


我这样做

const day:{date:Date, label:number, monthIndex:number, weekIndex:number , dayIndex:number} = {date:new Date(), label:label,monthIndex:0, weekIndex:indexes.weekIndex, dayIndex:indexes.dayIndex}

this.datepicker.daySelectHandler(day);

在你的 html 中更新 你必须以这种方式实现 datepicker

<bs-datepicker-container #datepicker></bs-datepicker-container>

在您的 ts 类中,您应该可以访问它

@ViewChild('datepicker') public datepicker:any;

推荐阅读