根据条件禁用动态复选框

根据条件禁用动态复选框

本文介绍了Angular 6:根据条件禁用动态复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有重复复选框列表的动态表单.请参阅 https://stackblitz.com/edit/angular-5jdnb5

I have a dynamic form with repeated checkbox list. Please see https://stackblitz.com/edit/angular-5jdnb5

如果在一个复选框列表中选中了一个复选框选项,则必须在其他列表中禁用相同的选项.例如,如果在第一个列表中选中选项 Life,则在其他列表中应禁用 Life 复选框.

If a checkbox option is checked in one checkbox list, the same option has to be disabled in other lists. For example, if option Life is checked in first list, the Life checkbox should be disabled in other lists.

我如何实现逻辑.请提出建议.

How do i implement the logic. Please suggest.

推荐答案

我创建了一个简化的演示 这里 可以被大众理解.

I have created a simpliifed demo HERE which can be understood by mass audience.

这里的主要概念是维护一个options对象和对应的list id,用于维护禁用哪个列表选项.

The main concept here is to maintain an object of options and the corresponding list id which is used to maintain which list option to disable.

无需在组件之间传递数据,只需对组件模板进行简单的对象操作即可启用/禁用复选框

No need to pass data between components, just simple object manipulation on the component template to enable/disable checkboxes

这篇关于Angular 6:根据条件禁用动态复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:50