angular - 无法为 ngx-bootstrap datepicker 动态设置属性

标签 angular typescript ngx-bootstrap

如果我理解正确,那么我们需要在 ngx-bootstrap datepicker 的输入元素中使用属性“bsDatepicker”。所以我想动态设置它的属性。

为了实现它,我正在使用 [attr.bsDatepicker]="bsDatepicker"但它将属性设置为小写,因此日期选择器无法正常工作。

enter image description here

我也试过 javascript setAttribute 但得到相同的结果是代码

isInputElement(elem: HTMLElement | null): elem is HTMLInputElement {
     if (!elem) {
      // null
        return false;
     }
  return (elem.tagName === 'INPUT')
}

setAttribute(id: any ){ 
const elem = document.getElementById(id);
console.log(elem);
if (this.isInputElement(elem)) {
  var att = document.createAttribute("bsDatepicker"); 
  att.value = "bsDatepicker";
  elem.setAttributeNode(att);
  console.log(elem);
} 

}

有没有其他方法可以使用日期选择器,或者我可以在驼峰式大小写中动态设置属性作为 ngx-bootstrap datepicker 所需的属性“bsDatepicker”。

最佳答案

   ngClass]="
                    condition
                      ? 'disabled'
                      : 'enable'
                  "

.disabled {
  pointer-events: none !important;
  cursor: default !important;
  opacity: 0.6 !important;
}

关于angular - 无法为 ngx-bootstrap datepicker 动态设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49808985/

相关文章:

javascript - 如何在 tsconfig.json 中排除以 '.spec.ts' 结尾的文件

javascript - getBBox() 和 getCompulatedTextLength() 一次有效,一次无效

javascript - Angular2 加载文件请求过多

Angular 2 - 如何在 ngx bootstrap/datepicker 中只显示月份和年份

Angular 形式不允许以空格开头的字段

javascript - 在 angular2 中使用 ngFor 不显示迭代名称

angular - 在 VS Code 中使用 Angular/CLI,我可以在构建的同时运行测试吗?

javascript - 以特定方式在JS中导入

angular - ngx Bootstrap 手动关闭按钮

javascript - 将上下文传递给 ngx bootstrap 的工具提示