I will answer your question. Почему не сделать проще и использовать переменную? as follows - { onlySelf?: boolean } is a unique parameter, parameters can be passed to different FormGroup and FormControl , but in fact we use AbstractControl methods, because everything from this class is inherited. Imagine this kind of form:
public form = new FormGroup({ name: new FormControl('Артур', { validators: [ Validators.required ] }), lastName: new FormControl('Фамилия', { validators: [ Validators.required ] }) });
Now the form is valid:
log(this.form.valid === true); // true
If we change the value of some control to null :
this.form.get('name') !.setValue(null);
That form will naturally become invalid:
log(this.form.invalid === true); // true
If you use the onlySelf parameter:
this.form.get('name') !.setValue(null, { onlySelf: true });
That will change the validity of only the control, but not the form itself:
log(this.form.valid === true); // true log(this.form.get('name') !.invalid === true); // true
setValue accepts other properties in the options object:
setValue(value: any, options: { onlySelf?: boolean, emitEvent?: boolean, emitModelToViewChange?: boolean, emitViewToModelChange?: boolean } = {}): void
This options parameter is passed down the chain, because the FormGroup is a tree, as well as with the markAsTouched method, setValue calls the updateValueAndValidity method where it passes options , updateValueAndValidity in turn checks the value for validity and calls markAsTouched on the control, where it also passes parameter these options, and now imagine if the usual variable was used instead of the object - there would be entropy.