Currently, I am utilizing Angular 8 with
"typescript": "~3.5.3"
. My objective is to handle the undefined collision in my code.
const { testLocation } = this.ngr.getState();
this.step2 = testLocation && testLocation.step2 ? testLocation.step2 : {};
this.$form = this.fb.group({
email: [this.step2.email || '', [Validators.required, Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]],
phone: [this.step2.phone || ''],
configuration: this.fb.group({
idTypesAccepted: this.buildIdentityDocumentTypeFormArr(this.identityDocumentType),
sessionOpenDays: [this.step2.configuration.sessionOpenDays || '', Validators.required],
sessionOpenHours: [this.step2.configuration.sessionOpenHours || '', Validators.required],
sessionOpenMinutes: [this.step2.configuration.sessionOpenMinutes || '', Validators.required],
sessionCloseDays: [this.step2.configuration.sessionCloseDays || '', Validators.required],
sessionCloseHours: [this.step2.configuration.sessionCloseHours || '', Validators.required],
sessionCloseMinutes: [this.step2.configuration.sessionCloseMinutes || '', Validators.required],
applicationExpiryDays: [this.step2.configuration.applicationExpiryDays || '', Validators.required],
applicationExpiryHours: [this.step2.configuration.applicationExpiryHours || '', Validators.required],
applicationExpiryMinutes: [this.step2.configuration.applicationExpiryMinutes || '', Validators.required],
paymentCloseDays: [this.step2.configuration.paymentCloseDays || '', Validators.required],
paymentCloseHours: [this.step2.configuration.paymentCloseHours || '', Validators.required],
paymentCloseMinutes: [this.step2.configuration.paymentCloseMinutes || '', Validators.required]
})
});
The issue lies in this.step2.configuration
where configuration is currently undefined. To overcome this issue, I need to either fill it up with an empty value or a value from this.step2.configuration
.