Angular reactive from after programmatically setting Value, the form remains in the same state until the end of the function, I don't understand this:
export class NewComponent {
constructor(
private fb: FormBuilder
){
}
profileForm = this.fb.group({
name: ['', Validators.required]
});
onButtonClick(){
this.profileForm.controls.topic.setValue('bla bla', {onlySelf: true});
console.log(this.profileForm);
}
}
// FormGroup {validator: null, asyncValidator: null, _onCollectionChange: ƒ, pristine: true, touched: false, …}
// asyncValidator: null
// controls: {topic: FormControl, hidden: FormControl, title: FormControl, language: FormControl, description: FormControl, …}
// errors: null
// pristine: true
// status: "INVALID"
// statusChanges: EventEmitter {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
// touched: false
// validator: null
// value: {title: ""}
// valueChanges: EventEmitter {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
// _onCollectionChange: () => this._updateDomValue()
// _onDisabledChange: []
// dirty: (...)
// disabled: (...)
// enabled: (...)
// invalid: (...)
// parent: (...)
// pending: (...)
// root: (...)
// untouched: (...)
// updateOn: (...)
// valid: (...)
// __proto__: AbstractControl
As you can see "value" still has {title: ""} controls.title.value has indeed changed but not value.
How do you make the changes persist? is the a "push()" of some sort? why is value not set and how do I correctly make it set?
because when you type into the form field the "value" object is updated as well and this one is the one you use to consult the state and is more appropriate for getter use-cases.
