在datepicker中添加TODAY和TOMORROW选项

时间:2018-05-23 18:48:38

标签: angular typescript datepicker ngx-bootstrap

我需要在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);
};

DatePicker

1 个答案:

答案 0 :(得分:0)

我是这样做的

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;