I am trying to validate my checkbox in a form with different fields, but the problem I am getting is that
HTML code:
<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 Code:
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);
}
I am trying to display whose are checked should be display on console by I am not getting the proper output, even the checkbox are not selected the "job_courses" is showing the "btech" I tried to check by check mba and btech its giving me random value i.e sometime btech sometime mtech.
What I am expecting is that what I checked should be display in console.
console.log('mtech', this.courses_btech);console.log('btech', this.courses_mtech);You are writing"mtech" + courses_btech, and vice versa.