timdeschryver / ng-signal-forms

105 stars 7 forks source link

How would you work with array's ? #20

Closed maku closed 8 months ago

maku commented 8 months ago

Is there a way to work with arraysf? (like https://angular.io/api/forms/FormArray)

goetzrobin commented 8 months ago

We have an array as part of the example app.

Here is how you would define the initial array: https://github.com/timdeschryver/ng-signal-forms/blob/8687663f7f4c544b6a8d56a98354748206424c3f/apps/example/src/app/simple-form.component.ts#L161

And then you can add new formFields/formGroups like seen here: https://github.com/timdeschryver/ng-signal-forms/blob/8687663f7f4c544b6a8d56a98354748206424c3f/apps/example/src/app/simple-form.component.ts#L189

goetzrobin commented 8 months ago

One thing I noticed is that the current implementation is using the mutate function, which will be removed as part of the v17 Angular release. I'll take a look and try to update the example to take that into account

maku commented 8 months ago

Yes, thank you very much for your reply. I've seen the sample code (and also the use of the "disappearing" mutate function). It seems that an additional layer of abstraction for array handling is not really necessary.

I am curious is ng-signal-forms somewhere in productive use?

timdeschryver commented 8 months ago

This package was originally intended as just a sandbox, but @goetzrobin made some great improvements and added more features to it to cover most use cases.

Maybe that @goetzrobin has a different opinion, but I'm not 100% sure that you should use it in a production environment. I also don't know the intentions/roam of the Angular team when it comes to forms. If you do want to use it, please try it out first before going all in. Just to be safe 😅

Keep in mind that there might be some breaking changes in minor releases.

goetzrobin commented 8 months ago

@timdeschryver agree absolutely! I would say use in production at your own risk and only if you could support the necessary maintenance.

That being said, I do absolutely believe this is the best way to deal with forms in Angular with signal support. With a "relatively" simple code base we already are able to cover majority of even complex form use cases in a declarative way.

maku commented 8 months ago

@timdeschryver @goetzrobin Thanks for your feedback...

I wouldn't use "ng-signals-form" as a solution in a large company either. But it will probably take a long time until the Angular team comes up with a modern “signal” based form solution (I guess not before ng19).

That's why I might try it out in my "private" application....

timdeschryver commented 8 months ago

That's nice to hear, feel free to open any issues with feedback. To keep the issue list clean I'm closing this issue.