[英]Angular: Uncheck Checkbox With [(ngModel)]
I have a form that contains a checkbox when I add [(ngModel)]
to the tag, the checkbox will be automatically checked when the page load 当我向标签添加
[(ngModel)]
时,我有一个包含复选框的表单,页面加载时将自动选中该复选框
<input type="checkbox" name="test" id="test" [(ngModel)]="model.test" value="1"> test
I tried to fix this using 我尝试使用修复此问题
ngOnInit() {
let test = document.getElementById('test') as HTMLInputElement;
test.checked = false;
}
in the .ts but didn't work 在.ts,但没有用
is there any way I can make the checkbox unchecked in the loading of the page? 有什么办法可以使页面加载中的复选框处于未选中状态?
The problem is your model, use: 问题是您的模型,使用:
model.text = false;
But in normal model must be: 但是在正常模型中必须是:
let model = [
{id: 1, label: "Check 1", checked: false},
{id: 2, label: "Check 2", checked: false},
{id: 3, label: "Check 3", checked: false}
];
你可以用
this.model.text = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.