html - 除非选中复选框,否则禁用按钮(Angular 7+)?

标签 html css angular typescript

除非所有复选框均已选中,否则我想禁用按钮?你如何在 Angular 中实现这个?

这是不同的,因为它不是一个表单,而且这个问题还没有得到解答,因为没有 for 循环。

    <div class="md-input-group md-checkbox md-input--nested-1">
      <input type="checkbox" class="md-input md-checkbox__input" id="checkboxNested1" name="checkboxNested1">
      <label style="margin-left: -30px;" class="md-checkbox__label" for="checkboxNested1">
        <p>Checkbox 1</p>
      </label>
    </div>

    <div class="md-input-group md-checkbox md-input--nested-1">
      <input type="checkbox" class="md-input md-checkbox__input" id="checkboxNested1" name="checkboxNested1">
      <label style="margin-left: -30px;" class="md-checkbox__label" for="checkboxNested1">
        <p>Checkbox 2</p>
      </label>
    </div>

   <button class="md-button" md-button color="red" aria-label="delete">Delete organization</button>


最佳答案

例如:Angular 2 Checkbox Two Way Data Binding .

export class FooComponenet {
   checkbox1 = false; // bind first checkbox
   checkbox2 = false; // another checkbox
}
<!-- or use (change)="methodName()" -->
<input type="checkbox" [checked]="checkbox1" (change)="checkbox1 = !checkbox1"/>
<input type="checkbox" [checked]="checkbox2" (change)="checkbox2 = !checkbox2"/>

<button [disabled]="!checkbox1 || !checkbox2">Bar</button>

<!-- or this -->
<button [attr.disabled]="!checkbox1 || !checkbox2">Bar</button>

您也可以使用:

关于html - 除非选中复选框,否则禁用按钮(Angular 7+)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59399089/

相关文章:

javascript - 何时以及为什么在 indexedDB 中调用 onupgradeneeded 方法?

html - 导航栏和标签 <ul> <li>

css - Windows 10 缩放默认高于 100% 导致网站大小问题

javascript - 如何更改 Bootstrap 导航栏的最小折叠

c# - 在 HTML 报告字段中显示尾随空格

angular - 当类具有计算属性时字段初始值设定项的简写

html - 添加 <form> 会破坏布局

javascript - Ho 在另一个 <div> 中检查一个 <div>

html - 学习编码时我必须花时间吗?

javascript - Angular:在 iFrame 中运行脚本