Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs accessing methods in another factory

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'
    }
  )
like image 658
map7 Avatar asked Dec 15 '22 12:12

map7


1 Answers

You only need to inject it:

.factory('test2', function (Common) {
  return {
    foobar: function () {
      Common.test();
    }
  };
})
like image 62
Josh David Miller Avatar answered Jan 12 '23 09:01

Josh David Miller