Michele Stieven
2 min readJun 28, 2020

--

Hi Tomas,

I don't really see why you're saying that CVA should be only used for single inputs/widgets. That's your preference, but CVAs can solve most of the problems with nested forms and imho they're actually better than your favorite approach :) To me, CVAs are *the* way to deal with nested forms. The technical difficulties you mention are kinda strange:

- It's not "much more verbose and complicated", it's in reality dead simple and almost always something you can just copy&paste from every other CVA implementation

- About manual propagation of events, the sub-form inside the CVA communicates with the parent form via the CVA interface: they're literally 4 methods, practically 4 lines of code you can also almost copy&paste

- If you want to show validations inside your sub-form, you just keep them as local state in the parent component (which is really simple thanks to RxJS) and you just pass them as an input to your component.

CVA has also other benefits, it works with Template AND Reactive forms and it avoids a LOT of bugs. It leads to better predictability as you have full control of the sub-forms (and their validation) in the parent. I personally don't like that thing you're doing via ViewChild, accessing the child component's method... Interfering with sub-classes that way is generally a bad practice.

Give CVAs another try! :) I worked with apps that were literally full of forms and CVAs saved the day. They're also one of my favorite parts of Angular itself. I also suggest you watch the talk of Kara Erickson at AngularConnect 2017 if you haven't seen it (you can find it on YT), which shown exactly what I mean.

Cheers!

--

--

Responses (1)