javascript - 如何使用角度6根据循环中的特定值禁用复选框?
问题描述
如果值 = 2,我想禁用复选框。这是我迄今为止尝试过的。
discheckcondition = [1,2,3];
for (let x = 0; x < this.discheckcondition.length; x++) {
// console.log(this.discheckcondition[x]);
if (this.discheckcondition[x] = '2') {
console.log(this.discheckcondition[x]);
this.disablecheckfornext = '1';
};
}
<ng-container *ngFor="let value of values;">
<label>
<input id="checkbox_group1" type="checkbox" pattern="[0-9]{10}" [disabled]=" disablecheckfornext == '1'" value="value.id" (change)="onCheckboxChange($event)"/>
</label>
</ng-container>
有人可以帮助我吗?这里的问题是所有文本框都被禁用了。
解决方案
如果 Checkbox 在 ngFor 循环中,此代码将起作用
discheckcondition = [1,2,3];
for (let x = 0; x < this.discheckcondition.length; x++) {
this.disablecheckfornext[x] = false;
if (this.discheckcondition[x] = '2') {
this.disablecheckfornext[x] = true;
};
}
<input id="checkbox_group1" type="checkbox" pattern="[0-9]{10}" [disabled]=" disablecheckfornext[#i]" value="" (change)="onCheckboxChange($event)"/>
推荐阅读
- java - 如何为时间戳签名启用 LTV 并设置不允许更改 pdf?
- java - 在 Linux 中以 1 KHz 频率调度任务
- wordpress - 主页重定向到未找到的其他位置
- asp.net - 如何使用社交 IdP 构建身份验证?
- python - 使用 imageio.readvol() 从文件夹中读取所有图像(jpg)
- powershell - 带有 CSV 文件的 Powershell 随机团队生成器
- ssl - svn 命令因 SSL 失败:Solaris 上的数据包长度错误
- python - 检测路线是否不是Flask中装饰器的最外层/错误“顺序”
- php - PHP:Guzzle 客户端 - 代理请求到不同的服务器
- angular - 这个在 Angular 中订阅 Observable 的箭头函数的正确解释是什么?