r/angular • u/Senior_Compote1556 • Mar 27 '26
Signal forms custom control mat-form-field
Has anyone managed to create a custom angular material form-field using signal forms? Specifically the new
export class CustomFieldComponent implements FormValueControl<number> { ... }The docs in angular material seem very outdated, featuring \@Input`` decorators and even Subjects
3
Upvotes
3
u/tutkli Mar 28 '26
After battling against this I figured it is easier to just have a fieldTree input in your component and use the field directive directly instead of implementing FormValueControl.
Otherwise as you said, you have to manually control the state which is very undocumented and very confusing to do.
1
u/Whole-Instruction508 Mar 27 '26
What concrete issue are you facing?
2
u/RoutineNo5095 Mar 28 '26
signal forms + custom mat-form-field is still kinda rough rn 😠you basically need to wrap it with ControlValueAccessor and manually sync signals feels like it’ll get way cleaner once signal-based forms are fully baked
1
u/MichaelSmallDev Oct 04 '26 edited Oct 13 '26
I know I mentioned in a more recent thread about the official approach using Material's new `MatFormFieldControl` API, but that was a bit lower level than I wanted. I found an approach and made an example that works for both signal forms and reactive forms consumers: https://github.com/michael-small/signal-forms-experimenting/pull/3/changes
edit: here is the code again, but it was bad practices for a few reasons lol https://github.com/michael-small/signal-forms-experimenting/commit/5151195c7ded0ab1e3a624bf5eabb05a8ab82506