[Angular] Improve template integration #1516
-
Hi, I'm new to TanStack Form and just started playing around with it. I use Angular as my framework. It seems there is "a lot of" boilerplate needed in the template to connect a field to an input. <input
[name]="fullName.api.name"
[value]="fullName.api.state.value"
(blur)="fullName.api.handleBlur()"
(input)="fullName.api.handleChange($any($event).target.value)"
/> If so, Angular supports handling this with a directive, for example import { Directive, inject } from '@angular/core';
import { TanStackField } from '@tanstack/angular-form';
@Directive({
selector: 'input[tanstackFieldInput]',
host: {
'[name]': 'field.api.name',
'[value]': 'field.api.state.value',
'(input)': 'field.api.handleChange($event.target.value)',
'(blur)': 'field.api.handleBlur()',
},
})
export class TanStackFieldInput {
protected readonly field = inject(TanStackField);
} Usage would then be: <input tanstackFieldInput /> And it would use the If there's interest in developing the integration of TanStack Form in Angular in a more "Angular way" (maybe like the My goal is to have the least amount of "code" inside the template. BTW: the class is called |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi! Reducing boilerplate is one of the ongoing projects at this time. React already has an implementation using If you want to contribute for the Angular implementation, I'm sure your effort will be greatly appreciated! As someone who has never programmed with Angular, I can't give proper feedback for your suggestion. However, I can give you reference points to consider for the Angular implementation based on what the React version did:
The entire AppForm lives inside the React adapter. There are no form core changes as of v1.11.2 . The directive sounds like an interesting approach. If you think it combines flexibility with reducing boilerplate, it is definitely worth looking into. |
Beta Was this translation helpful? Give feedback.
-
Hey @flensrocker, glad to see you here! I'd love to give some thoughts on your proposed API design, as well as the three major options I investigated for our Angular adapter. Concerns on your proposalPer our philosophy doc, I see two major problems with the proposed API:
As such - despite good intentions and a good idea broadly - I'm not sure this specific API suites our needs. Other explored optionsAs mentioned earlier, we explored many alternative APIs to make this work the way we think would be ideal with our engineering philosophy. 1a) Alternative
|
Beta Was this translation helpful? Give feedback.
For those who are interested: @crutchcorn and I had a little session to explore this idea. You can find the draft at #1541
That was fun!