I try to use the reactive form and I need to create only the key for each item that is filled But because the first moment is created, if the field is not full, it sends null While I want a field that is not empty to be sent at all my code is:
form: FormGroup;
constructor() {
this.form = new FormGroup({
basePrice: new FormControl(null, [customeValidator.numberOnly()]),
discountValue: new FormControl(null, [customeValidator.numberOnly()]),
roomViewCount: new FormControl(null, [customeValidator.numberOnly()])
});
}
onCalcute() {
console.log(this.form.value);
if (this.form.valid) {
this.roomData = {
basePrice: this.form.value.basePrice,
discountValue: this.form.value.discountValue,
roomViewCount: this.form.value.roomViewCount
};
this.clicked = true;
}
}
if just one of them was full console.log return
{
basePrice: 20,
discountValue: null,
roomViewCount: null
}
but I need:
{
basePrice: 20
}