我目前正在使用debounceTime(400)
作为解决方法。我试图获取FormGroup.valueChanges
的最后一个发出的值,该值在启动时会触发6次。我希望它仅使用最后发出的值触发一次。
listenToFormChanges(): void {
this.requestFormGroup.valueChanges.pipe(SwitchMap(data => of (data)), ).subscribe(
(data: any) => {
if (this.model.isEditable) {
this.model.requestType = data.requestType;
this.model.requestDeviceType = data.requestDeviceType;
this.model.requestSubtype = data.requestSubtype;
this.model.requestDeviceSerialNumber = data.requestDeviceSerialNumber;
this.model.title = data.title;
this.model.phase = data.phase;
this.model.quantity = data.quantity;
this.model.description = data.description;
this.model.pickupLocation = data.pickupLocation;
this.model.state = data.state;
this.model.priority = data.priority;
this.model.team = data.team;
this.isChanged = this.isFormChanged(this.originalRequestFormGroup, this.requestFormGroup);
}
}
);
}