为什么我的角形式控制不给正确的值?

  • 本文关键字:控制 angular typescript
  • 更新时间 :
  • 英文 :


我已经这样设置了一个表单组:

controls = {
type: new FormControl(),
attendanceDate: new FormControl(),
status: new FormControl(),
}
form = new FormGroup(this.controls);

这是类型控件的html:

<div id='form' [formGroup]="form" [appChangesPendingSection]="form.dirty">
<div id="overlay" *ngIf="(this.showOverlay)"></div>
<bi-dropdown-single i18n-label label="Type" formControlName="type" [required]="true">
<bi-option *ngFor="let calendarItem of calendarItemTypes$ | async" [value]="calendarItem">{{calendarItem.name}}
</bi-option>
</bi-dropdown-single>
<ng-container *ngIf="(isDuplicateAttendance$ | async) === true">
<span i18n class="invalid-feedback d-block">There is already an attendance record for this type and date. If you
need to
replace this result, you will need to hide the old result first.</span>
</ng-container>

我有一个on change function:

onAttendanceFormChanges(): void {
this.subscriptions.push(this.controls.attendanceDate.valueChanges.subscribe(() => {
this.subscriptions.push(this.$spService.clientAttendance$.subscribe(attendances => {
if (this.controls.attendanceDate.value) {
if (this.isAttendanceDuplicate(this.controls.attendanceDate.value, this.controls.type.value, attendances)) {
this.isDuplicateAttendance$.next(true);
this.controls.attendanceDate.setErrors({ 'duplicate': true });
} else {
this.isDuplicateAttendance$.next(false);
this.controls.attendanceDate.setErrors(null);
}
}
}));
}));
}

我称之为。isAttendanceDuplicate,在第二个参数中传入类型值。

函数的前两行:

isAttendanceDuplicate(date: Date, type: number, attendances: Attendance[]): boolean {
console.log("number " + type)

console.log的响应是"number [object object]",而不是"number 1",其中1对应于被选中的下拉菜单中的第一项。为什么我得到的是[object object] ?

在此

<bi-option *ngFor="let calendarItem of calendarItemTypes$ | async" [value]="calendarItem">{{calendarItem.name}}
</bi-option>

我应该这么做的

[value]="calendarItem.id"

最新更新