angular - 在 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);
};
解决方案
我这样做
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;
推荐阅读
- sql - 将连接中的逗号分隔值插入特定列
- javascript - 对象数组中的特定数据
- wordpress - woocommerce REST API 请求购买单品
- sympy - 为什么 sympy count_ops() 因集成而失败?
- php - 仅使用 PHP 列出来自 FTP 服务器的文件夹
- python-3.x - TensorFlow 中更快的 K-Means 聚类
- sql - SQL 查询未返回预期结果
- php - 未定义函数 mssql_connect() Codeigniter 3.0 + Azure 数据库 + 000webhost + PHP 5.6
- ruby-on-rails - 如何在 Jbuilder 中合并 JSON 对象
- php - Index.php 登录功能修复