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'
}
)
You only need to inject it:
.factory('test2', function (Common) {
return {
foobar: function () {
Common.test();
}
};
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With