【发布时间】:2018-06-26 19:33:43
【问题描述】:
我正在尝试在具有不同字段的表单中验证我的复选框,但我遇到的问题是
HTML 代码:
<div class="form-group">
<label class="login_label">Courses</label>
<span style="color:#00bfff">*</span>
<input [ngModelOptions]="{standalone: true}" [(ngModel)]="courses_mba" type="checkbox" class="" value="mba">Mba
<input [ngModelOptions]="{standalone: true}" [(ngModel)]="courses_btech" type="checkbox" class="" value="btech">Btech
<input [ngModelOptions]="{standalone: true}" [(ngModel)]="courses_mtech" type="checkbox" class="" value="mtech">Mtech
</div>
Ts 代码:
if (this.jobForm.invalid && (this.courses_mba === undefined || this.courses_btech === undefined || this.courses_mtech === undefined)) {
this.snackBarService.requiredValue(' Please complete the form');
} else {
this.job_courses = this.courses_mtech ? 'mtech' : '' + this.courses_btech ? 'btech' : '' + this.courses_mba ? 'mba' : '';
this.snackBarService.requiredValue(' form Submitted Successfully');
console.log('CArray', this.job_coursess);
console.log('Course', this.job_courses);
console.log('mba', this.courses_mba);
console.log('mtech', this.courses_btech);
console.log('btech', this.courses_mtech);
}
我试图通过我没有得到正确的输出来显示应在控制台上显示的被选中的对象,即使未选中复选框 "job_courses" 正在显示 "btech" 我试图通过检查 mba 和 btech 进行检查它给了我随机值,即有时是 btech,有时是 mtech。
我期望的是我检查的内容应该显示在控制台中。
【问题讨论】:
-
这里有些错别字:
console.log('mtech', this.courses_btech);console.log('btech', this.courses_mtech);你写的是"mtech" + courses_btech,反之亦然。 -
这里我只是检查一下btech,mtech的价值是什么
-
请发minimal reproducible example 显示问题。
标签: javascript angular checkbox