Is it possible to make my dependencies interchangeable in AngularJS? For example, if I have a service named myService stored within the module myDependency, how can I switch out myDependency with a new service without disrupting the main application?
Should I simply create an identical module for the new service to override the old one, or is there a way to reference the module to a $variable and update that variable with the new service?
The goal here is to seamlessly integrate a new module JavaScript file that supersedes the existing module.
//Main application
var app = angular.module('tswp',['myDependency'])
.controller('MyAPP',function(myService){
console.log(myService.run());
}
//Old dependency
angular.module('myDependency',[])
.service('myService',function(){
this.run = function(){
console.log("1")
}
})
//New service intended to replace the old service
angular.module('myReplacementModule',[])
.service('myService',function(){
this.run = function(){
console.log("2")
}
})