Skip to content

Instantly share code, notes, and snippets.

@SelrahcD
Last active December 31, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SelrahcD/8009538 to your computer and use it in GitHub Desktop.
Save SelrahcD/8009538 to your computer and use it in GitHub Desktop.
var module = angular.module('Test', []);
module.service('TestService', ['ServiceA', function(serviceA) {
}]);
module.service('ServiceA', function() {
// First implementation of Service A
});
module.service('ServiceABis', function() {
// Second implementation of Service A
});
Every time ServiceA is needed as a dependecy inject ServiceABis instead of ServiceA, for instance in TestService.
@ithinkdancan
Copy link

why would you not want serviceA?

@christophehurpeau
Copy link

var module = angular.module('Test', []);

module.service('TestService', ['ServiceA', function(serviceA) {
}]);

var ServiceA = window.location.search === '?IWantServiceABis' ? function() {
// Second implementation of Service A
} : function() {
// First implementation of Service A
};

module.service('ServiceA', ServiceA);

@SelrahcD
Copy link
Author

@ithinkdancan The issue came up when I was working without an Internet access and needed to request upon an API. I wanted to make a service returning fake data.

@christophehurpeau I think this would make our good friends cry too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment