-
Notifications
You must be signed in to change notification settings - Fork 2k
reason for not using resolve for list articles #1662
Comments
Resolve gets an article according to its ID in the route parameter and provides it to the controller. It keeps the controller clean by not involving $stateParams and promised-based code there. But for the articles list page we want an array of articles, so the service is called without parameters from the controller. I agree that the organisation is somewhat confusing, I think it's used just to cut down on code but doing both queries in the controller would also be acceptable. |
To further @hyperreality's point. Adding the service call to the Article's list route configuration, would also be acceptable. To answer your specific question: I don't think there was any particular reason that the service call was put in the controller. I don't see a benefit, or reason, for doing it in either place over the other. |
@jiffify I'm going to close this, but feel free to add feedback here. Thanks. |
Thanks guys I had couple of thoughts, first for consistency I though all service calls should be in one place and second since the query returns an array, so I though may be that is a reason for putting it in controller rather than route config. either way, thanks for clarification. |
After thinking about this some more, it may be better to have the controller make the service call in the case of retrieving an array of data. Since technically, your view/controller doesn't need to have the full collection loaded for it to work. However, in the case of a single resource, more than likely you need to have it already loaded for the view/controller to properly function. I wouldn't put any importance on having all service calls in one place. It's just important that all your logic/data-access code is put into services. You can use your services anywhere you like. |
Hi,
Just wondering, is there a reason for not using resolve for list articles inside the route configurations. I see list service is being called in the controller.
Thanks..
The text was updated successfully, but these errors were encountered: