Let's imagine a scenario where there is a module containing only one factory, which serves as the shared service.
angular.module('sharedService', [])
.factory('sharedSrv', sharedService)
function sharedService() {
var number;
return {
getNum: getNumber
};
function getNumber() {
return number;
}
function setNumber(i) {
number = i;
}
}
I have observed that we can inject shared services by including them as dependencies in a module.
angular.module('app', ['sharedService'])
.controller('theCtrl', function(sharedSrv) {
var self = this;
self.setSharedNumber = sharedSrv.setNumber;
}
However, how do we inject a shared service if a controller needs to use services specific to its own module?
angular.module('app', ['sharedService'])
.controller('theCtrl', theCtrlFun)
.service('theSrv', theSrvFun)
theCtrlFun.$inject = ['theSrv']
function theCtrlFun(localSrv) {
// How can we access the shared service here?
}
function theSrvFun() {
// Adding some awesome functionalities.
}
Your assistance on this matter would be greatly appreciated.