lundi 26 août 2019

Angula 2 Reactive Forms need service injection

I'm working in a project where we have lot of complex forms, so normally I create an extended class from FormGroup, and create getters for all my properties and everthing I need.

Sometimes I need to inject any service into that form class to get some information needed for the form creation. As my forms are not injectables() I have to pass manually those service thought the constructor... but that is not nice to me... it make the creation of the form a bit odd.

So, to make it better, I normally create a FactoryForm which I make it @injectable(). That way I can simply use the factory creation methods for my form creation, as I can inject anything in my factory, and I can make transparent for anybody that some service injections are taking place. I want to keep my form creation as easy as possible.

Do you know a better way? I feel that the pattern I'm using is still to much complicate.

Aucun commentaire:

Enregistrer un commentaire