Angularjs accessing methods in another factory

angularjs, coffeescript, javascript

Solution

You only need to inject it:

.factory('test2', function (Common) {
  return {
    foobar: function () {
      Common.test();
    }
  };
})

Problem

I've got an AngularJS model in which I've created a module called myService to hold some commonly used code which I use throughout my application. My Common factory is where I've been adding all my methods and now I want to split this up and give them good names. A lot of my methods call each other so how can I call a method which is in another factory? ``` angular.module('myService', ['ngResource']) .factory('test2', ($window) -> return { foobar: () -> Common.test() } ) .factory('Common', ($window) -> return { test: () -> alert 'testing' } ) ```

Original source