I have the formGroup bellow that i call in the method saveConvention, i want to get the group contract and edit the formControl conventionId in the createConvention service, i tried with the method mentioned bellow but when i try to display, conventionId is always null
this.conventionForm = this.fb.group({
shortname: fb.control(null, Validators.required),
fullname: fb.control(null, Validators.required),
contract: this.fb.group({
conventionId: fb.control(null),
signatureProvides: fb.control(null, Validators.required)
})
});
public saveConvention(data: FormGroup): void {
let currentData: FormGroup = data;
let formControlContract: AbstractControl = currentData.get('contract');
data.removeControl('contract');
this.conventionService.createConvention(data.value)
.catch(err => {})
.subscribe(res => formControlContract.patchValue({ conventionId: res.id }) );
console.log(formControlContract.value);
this.contractBenefitPartnerService.createContract(formControlContract.value)
.catch(err => {}).subscribe(res => {});
}
try:
formControlContract.patchValue({ contract: {conventionId: res.id }})
You will need to use updateValueAndValidity
after using patchValue for it to take effect.
this.conventionService.createConvention(data.value)
.catch(err => {})
.subscribe(res => {
formControlContract.patchValue({ conventionId: res.id })
formControlContract.updateValueAndValidity();
}
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.