i need to pass enum type
to server . but when i send the form to server it send enum fild
by type string
.
this is my enum :
export enum PayTypes {
Free,
Subscribe
}
and this is my form :
createForm(): void {
this.lessonAddForm = new FormGroup({
payType: new FormControl('', Validators.required),
});
}
addLesson(): void {
const payString = PayTypes[this.lessonAddForm.controls['payType'].value];
const payType: PayTypes = PayTypes[payString];
this.lessonAdd = this.lessonAddForm.value;
this.lessonAdd.payType = payType;
this.subscriptions = this.lessonService
.add(this.lessonAdd)
.subscribe(
res => {
if (res.success === true) {
this.alertService.success('', 'GENERAL.ADD_SUCCESS');
this.backToMenu();
}
}
);
}
and i try for convert string to enum by this way :
const payString = PayTypes[this.lessonAddForm.controls['payType'].value];
const payType: PayTypes = PayTypes[payString];
this.lessonAdd = this.lessonAddForm.value;
this.lessonAdd.payType = payType;
but it not work .
How can i solve this Problem????