【问题标题】:Set default return Value to false of Checkbox when untouched未触摸时将默认返回值设置为复选框的 false
【发布时间】:2021-12-21 09:54:48
【问题描述】:

我想将我的 Angular Checkbox 的默认值设置为 false(如果 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>

【问题讨论】:

    标签: angular checkbox default


    【解决方案1】:

    解决此问题的最简单方法是在 set(Notification) 方法中添加 If 语句。这样代码会检查 Value 是否为 null,如果为 true,则将 Value 更改为 false:

        public setNotification(notificationInfo: FormNotificationInfo): void {
                if (notificationInfo.notification === null) {
                        notificationInfo.notification = false;
                }
                this.notificationInfo= notificationInfo;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多