我注意到,当我尝试通过HTTPclient提交FormBuilder
中的几个值时,我的值没有更新。当我第二次运行提交时,这些值会更新。
private mergeDates(dateValue: string, timeValue: string): string {
const returnValue = dateValue.toString().replace(' 00:00', ` ${timeValue}`);
return returnValue;
}
private submitVacancy() {
if (this.vacancyForm.invalid) {
return;
}
const fValue = this.vacancyForm.value;
const fControls = this.vacancyForm.controls;
fControls['beginDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['beginTime']),
);
fControls['endDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['endTime']),
);
alert(JSON.stringify(fValue));
this.http.post(`${this.apiUri}/addvacancy`, JSON.stringify(fValue));
}
答案 0 :(得分:1)
我像Mateusz建议的那样在代码中添加了以下行,现在可以正常工作了。 我的代码现在看起来像这样。
public static long noOfCombinations(int n, int m){
//this part is for fewer multiplications
//b/c 4 out of 6 has the same number of combinations as 2 out of 6
if (m > n) {
return 0;
} else {
if ((n - m) > m) {
return noOfCombinations(n, (n - m));
}
}
long numerator = 1;
long denominator = 1;
//these two loops are for partial factorial
for (int i = n; i > m; i--) {
numerator *= i;
}
for (int i = (n - m); i > 1; i--) {
denominator *= i;
}
// no of combinations
return numerator / denominator;
}
我运行private mergeDates(dateValue: string, timeValue: string): string {
const returnValue = dateValue.toString().replace(' 00:00', ` ${timeValue}`);
return returnValue;
}
private submitVacancy() {
if (this.vacancyForm.invalid) {
return;
}
const fControls = this.vacancyForm.controls;
let fValue = this.vacancyForm.value;
fControls['beginDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['beginTime']),
);
fControls['endDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['endTime']),
);
fValue = this.vacancyForm.value;
alert(JSON.stringify(fValue));
console.log(JSON.stringify(fValue));
this.http.post(`${this.apiUri}/vacancy`, JSON.stringify(fValue));
}
之后立即添加了fValue = this.vacancyForm.value;
。