Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

reason for not using resolve for list articles #1662

Closed
jiffify opened this issue Dec 2, 2016 · 5 comments
Closed

reason for not using resolve for list articles #1662

jiffify opened this issue Dec 2, 2016 · 5 comments
Assignees
Milestone

Comments

@jiffify
Copy link

jiffify commented Dec 2, 2016

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..

@hyperreality
Copy link
Contributor

hyperreality commented Dec 2, 2016

function getArticle($stateParams, ArticlesService) {
  return ArticlesService.get({
    articleId: $stateParams.articleId
  }).$promise;
}

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.

@mleanos
Copy link
Member

mleanos commented Dec 2, 2016

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.

@mleanos mleanos added this to the q milestone Dec 2, 2016
@mleanos mleanos self-assigned this Dec 2, 2016
@mleanos
Copy link
Member

mleanos commented Dec 2, 2016

@jiffify I'm going to close this, but feel free to add feedback here. Thanks.

@mleanos mleanos closed this as completed Dec 2, 2016
@jiffify
Copy link
Author

jiffify commented Dec 4, 2016

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.

@mleanos
Copy link
Member

mleanos commented Dec 4, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants