Can Angularjs reuse a service across several ng-apps

前端 未结 1 381
醉酒成梦
醉酒成梦 2021-02-02 17:09

I am trying to create a web app that will use several angular ng-apps, and at least two can use the same service code (they DONT need to share the data, but they perform similar

相关标签:
1条回答
  • 2021-02-02 17:31
    angular.module('myReuseableMod', []).factory('myReusableSrvc', function() {
        // code here
    });
    
    var App1 = angular.module('myApp1', ['myReuseableMod']);
    App1.controller('someCtrlr', ['$scope', 'myReusableSrvc', function($scope, myReusableSrvc) {
        // controller code
    }]); // end someCtrlr
    
    var App2 = angular.module('myApp2', ['myReuseableMod']);
    App2.controller('someCtrlr', ['$scope', 'myReusableSrvc', function($scope, myReusableSrvc) {
        // controller code
    }]); // end someCtrlr
    
    0 讨论(0)
提交回复
热议问题