2014-06-06 57 views

回答

0

只需將所有依賴服務注入到您想創建的umberlla服務中,如下所示。

使用umberlla服務:

app.controller('MainCtrl', function($scope, umb) { 
    $scope.name = 'World'; 
    console.log(umb.serv1.obj); 
    console.log(umb.serv2.obj); 
}); 

共同服務:

app.service('serv1', function() { 
    var me =this; 
    me.obj ='Im from service 1'; 
    return me; 
}); 

app.service('serv2', function() { 
    var me =this; 
    me.obj ='Im from service 2'; 
    return me; 
}); 

Umberlla服務: app.service( 'UMB',函數(SERV1,serv2上){

var me = this; 
    me.serv1 = serv1; 
    me.serv2 = serv2; 
    return this; 
}); 

示例演示:http://plnkr.co/edit/MIZTYdz4OsuR0S89n5kG?p=preview