0

I have a service with a few methods:

function userService($http, API, auth) {
   ....
}

and then used in my module like:

var app = angular.module('app', ['ngRoute'])
   .service('user', userService)
   ...

All of this is in my app.js file, I want to separate things so its easier to maintain. I'm trying to use the line .service('user', '/services/userService') but its not working any ideas how to i need to reference this?

Thanks.

4
  • isn't that should be require('/services/userService')? Commented Jan 10, 2016 at 11:42
  • I tried that at he top of the app.js file. doesn't work Commented Jan 10, 2016 at 11:54
  • I meant to say .service('user', '/services/userService') should be require('/services/userService') Commented Jan 10, 2016 at 11:56
  • But then at what point would the keyword 'user' be set? Commented Jan 10, 2016 at 12:00

1 Answer 1

1

I think you are creating a new module instead of use yours.

To retrieve an existing module and use it in a separated file, you have to do :

var app = angular.module('app')
    .service('user', userService')
    // ...

Instead of

var app = angular.module('app', ['ngRoute'])
    .service('user', userService')
    // ...

Documentation available at https://docs.angularjs.org/guide/module#creation-versus-retrieval

EDIT from @koox00 answer

Don't forgot to load all files related to your module in your markup, in the good order (before load the file containing your module declaration).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.