A
A
andreys752019-09-11 12:36:18
Angular
andreys75, 2019-09-11 12:36:18

Where is the best place to load data into complex models in Angular?

Good afternoon, I continue to refactor someone else's code.
There is a main component, and it has a main model. Different services are used to fully load the model, to load data from different tables and substituting data into the fields of the main model, moreover, there is still a bunch of additional logic for creating a new object or loading an existing one, depending on the data loaded at the initial stage. And all this code is in the component.
The question is, where is it better to transfer all this to the model or to the service?
I ask because I mostly see examples of very simple models, in fact, an interface with a description of the data, and I need to inject all auxiliary services into the main model and import all auxiliary models.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2019-09-12
@ozknemoy

It's hard to advise without code. in the guides they write to take it to the service. I don't think there is a clear answer. if this is a small component and the code is used only in it, then it makes no sense to take it out to the service. if it is a bulky (view) component and it is overloaded with logic, then it should definitely be taken out to the service. or split a thick component into smaller ones (without fanaticism), which I personally prefer myself. a clean controller is a sign of good architecture

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question