Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where to put services that don't have controllers neither views? #694

Closed
andreshg112 opened this issue Mar 21, 2016 · 3 comments
Closed

Comments

@andreshg112
Copy link
Contributor

For example: I have a StatesService. It returns all states of a country, but It doesn't have its own view.

  1. If It's only used in one view, should I put it into the subfolder of that view?
  2. If It's used in many views, where should I put it?

In "Folder-by-feature" https://github.com/johnpapa/angular-styleguide/tree/master/a1#folders-by-feature-structure, It can see a 'services' folder, but not in image below.

For moment, I'm using an "extra" folder to put services with no controllers nor views.

@johnpapa

@bampakoa
Copy link

  1. That's correct
  2. You should put it in the core service file core.service.js

@mattgrande
Copy link
Contributor

I have a services directory that stores all of my common services.

Personally, I wouldn't put it in a "core service" file, because that seems like it would violate the Rule of 1 (Y001).

@johnpapa
Copy link
Owner

Services don't relate to one View, they relate to a service or set of actions that they help provide for an app. So your scenario is quite common. You're already more than half way there :)

First we decide if we have the need for a service. You already did that with determining it handles state.

Then we decide how to extract ust that logic. You did that too!

Then we decide who needs it. Is it used by 1 controller? 1 service? 1 directive? Are they all in 1 feature/module? If used by one module I put it in that module. If used across the app, put it in a shared module.

Good luck

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

No branches or pull requests

4 participants