【问题标题】:Turn checked state to false after closing a modal关闭模式后将选中状态变为 false
【发布时间】:2020-01-17 05:11:17
【问题描述】:

我正在使用 Angular 8 在模态中实现引导开关。

默认情况下,它处于off 状态,但是当我打开它on 并关闭模式时,它仍然处于on 状态。

HTML:

<div align="center" class="custom-control custom-switch">
 <input type="checkbox" class="custom-control-input" id="customSwitches">
 <label class="custom-control-label" for="customSwitches">Try it</label>
</div>

TS 代码:

ngAfterViewInit(): void {

    $('#modalDisplay').on('hidden.bs.modal', function () {
      $('#customSwitches').attr(':checked', false);
    }.bind(this));
}

【问题讨论】:

  • 在 Angular 中使用 jQuery 是不好的做法...请从:stackoverflow.com/questions/42097796 寻求帮助
  • 我通过使用“.prop”解决了这个问题,插入了实际的“.attr”

标签: jquery html angular bootstrap-4


【解决方案1】:

我通过使用“.prop”解决了这个问题,插入了实际的“.attr”

即使他们的页面显示“状态”是一个属性,但使用属性它修改了按钮。

ngAfterViewInit(): void {

    $('#modalDisplay').on('hidden.bs.modal', function () {
      $('#customSwitches').prop(':checked', false);
    }.bind(this));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-12
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多