【问题标题】:Add TODAY and TOMORROW options in datepicker在 datepicker 中添加 TODAY 和 TOMORROW 选项
【发布时间】:2018-05-23 18:48:38
【问题描述】:

我需要在 ngx-bootstrap 日期选择器中添加 TODAY 和 TOMORROW 选项。为此,我更改了bs-current-date-view.component.js 中的以下代码@ 987654324@ 中的代码

 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);
};

【问题讨论】:

    标签: angular typescript datepicker ngx-bootstrap


    【解决方案1】:

    我是这样做的

    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;
    

    【讨论】:

    • 按你说的试过了,还是不行。你能解释一下我需要做什么吗
    • 我在使用您的解决方案时遇到了label not definedindexes not defined 错误。并且还得到Cannot read property "daySelectHandler" of undefined 作为控制台错误
    • @Krishna 请查看更新信息,希望对您有所帮助
    猜你喜欢
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 2017-06-07
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多