[英]Set default return Value to false of Checkbox when untouched
I want to set the default value of my Angular Checkbox to false (if the Checkbox is untouched).我想将 Angular Checkbox 的默认值设置为 false(如果 Checkbox 未受影响)。 Is there a simple solution for this?有没有一个简单的解决方案?
My checkbox:我的复选框:
<div class="notificationTitle margin-top-2">
<div class="row">
<div class="col-md-12">
<div>
<label class="text-h4 margin-top-2"
for="notifcation"></label>
<input
[formControlName]="InputField.Notification"
[name]="inputField.Notification"
id="notifcation"
type="checkbox"
>
</div>
</div>
</div>
The simplest way to solve this Issue is to add a If statement in the set(Notification) Method.解决此问题最简单的方法是在 set(Notification) 方法中添加 If 语句。 That way the code checks if the Value is null, if thats true then it changes the Value to false:这样,代码检查值是否为空,如果为真,则将值更改为假:
public setNotification(notificationInfo: FormNotificationInfo): void {
if (notificationInfo.notification === null) {
notificationInfo.notification = false;
}
this.notificationInfo= notificationInfo;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.