我已经声明了一个简单的形式,并为其分配了一个可观察对象,该可观察对象被映射为返回对象,我在返回之前在控制台中记录了该对象,但值更改从未触发。
comPlanForm= new FormGroup({
commissionPlanType: new FormControl('', [Validators.required]),
commissionPlanName: new FormControl('', [Validators.required, Validators.maxLength(150)]),
commissionPlanDescription: new FormControl('', [Validators.maxLength(150)]),
payoutSchedule: new FormControl('', [Validators.required]),
broker: new FormControl('', [Validators.required]),
trigger: new FormControl('', [Validators.required]),
waitUntilDays: new FormControl('', [Validators.required]),
startDate: new FormControl('', [Validators.required]),
endDate: new FormControl('')});
comPlanForm$ = this.comPlanForm.valueChanges.pipe(
map(value => {
const plan= new CommissionPlanRequest(null,null,value.commissionPlanName, value.commissionPlanDescription,
value.commissionPlanType, value.startDate, value.endDate, value.payoutSchedule, value.broker, null,
new PlanTrigger(null,value.waitUntilDays,value.trigger),[])
return plan;
}),
tap(x=>console.log(x))
);
我没有ngOnInit,我也尝试过将console.log放入map函数本身,但不走运,关于为什么我的值更改未触发的任何想法吗?
答案 0 :(得分:-2)
this.comPlanForm.valueChanges.subscribe(value =>
{
const plan= new CommissionPlanRequest(null,null,value.commissionPlanName, value.commissionPlanDescription,
value.commissionPlanType, value.startDate, value.endDate, value.payoutSchedule, value.broker, null,
new PlanTrigger(null,value.waitUntilDays,value.trigger),[])
this.comPlanForm$ = plan;
}
);