除非所有复选框均已选中,否则我想禁用按钮?你如何在 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>
您也可以使用:
- 模板驱动 ( https://angular.io/guide/forms ) 或响应式表单 ( https://angular.io/guide/reactive-forms )
- 表单验证器 ( https://angular.io/guide/form-validation )
关于html - 除非选中复选框,否则禁用按钮(Angular 7+)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59399089/