I have a Reactive Form like this :
this.editform = new FormGroup({
'username' : new FormControl(null,[Validators.required]),
'password' : new FormControl(null,[Validators.required]),
'full_name' : new FormControl(null,[Validators.required]),
'avatar' : new FormControl(null,[Validators.required]),
});
In onSubmit() function, I create a variable named submitValue and pass form value to this varibale:
onSubmit() {
const submitValue = this.editform.value
submitValue.username = 'Jon';
console.log(this.editform.value.username) // Output : 'Jon' [The value of editform also changed]
}
But whenever I change submitValue value, the editForm value also changed. I only want to get form value from edit form and handle it in submitValue. Is there anyway that I can do it.
const submitValue={...this.editform.value}(a copy of the object)?