Redefining AngularJs Services

I am making an AngularJs module. The fact is that this module should work with another module (its as a plugin). Therefore, I mainly import this module from another module later. However, there are some services in this module that I would like to override later from the module that imports this module. How can I do it? Will it just define another service with the same name? If so, how do I get the original service?

+6
source share
1 answer

Cancellation will occur depending on the order in which the modules are created. The last module created will take precedence over modules with duplicate services created before it.

SO link regarding service namespace: "Namespacing" services in AngularJS

Plunker: http://plnkr.co/edit/P488AkNtGYGUXmo9gIAT?p=preview

var dep1 = angular.module("dep1",[]); var dep2 = angular.module("dep2",[]); var app = angular.module("app",["dep2","dep1"]); dep1.factory("helloSrvc",function(){ return { msg: "hello from dep1" } }); dep2.factory("helloSrvc",function(){ return { msg: "hello from dep2" } }); app.controller("myCtrl", function(helloSrvc,$scope){ $scope.msg = helloSrvc.msg; }); angular.bootstrap(document,["app"]); 
+4
source

Source: https://habr.com/ru/post/976971/


All Articles