This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
Control type doesn't work with setValue #76
Labels
Comments
Use |
So what should I use? |
const form = new FormGroup<{ skills: string[] }>({
skills: new FormArray([new FormControl('a'), new FormControl('b'), new FormControl('c')]),
});
form.setValue({ skills: ['1', '2', '3'] }); |
KostyaTretyak
added
project: forms
Relates to the project forms
type: discussion / question
Further information is requested
labels
Jun 30, 2020
Why you're closing the issue? This is not the intended behavior. I have a FormControl with an array value. |
A custom control accessor can be FormControl that takes an array. |
KostyaTretyak
added
type: bug/fix
Something isn't working
and removed
type: discussion / question
Further information is requested
labels
Jun 30, 2020
Sorry. In my practice, it has not been the case that |
You can do this: const form = new FormGroup<{ skills: Control<string[]> }>({
skills: new FormControl(['a', 'b', 'c']),
});
form.get('skills').setValue(['1', '2', '3']); |
Yes, but In reality, I have more properties in the group so it's more convenient to use setValue on the group. I'll wait for a fix. Thanks. |
Having the same problem interface ProfileForm {
name: string;
availableWays: Control<Way[]>;
displayedWays: Control<Way[]>;
}
this.form = this.fb.group<ProfileForm>({
name: [{value: '', disabled: true}],
availableWays: [{value: [], disabled: true}],
displayedWays: [{value: [], disabled: true}]
});
this.form.reset({
name: '',
availableWays: [...this.ways], // ERROR : Type 'Way[]' is not assignable to type 'Control<Way[]>'. Property '[sym]' is missing in type 'Way[]' but required in type 'UniqToken'.
displayedWays: [], // ERROR : Type 'Way[]' is not assignable to type 'Control<Way[]>'. Property '[sym]' is missing in type 'Way[]' but required in type 'UniqToken'.
}); This is working : this.form.reset({
name: '',
availableWays: [...this.ways],
displayedWays: [],
} as ProfileForm); |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
I have the following form:
And I get an error from
setValue
.The text was updated successfully, but these errors were encountered: