作者:暖暖de苹果的马甲 | 来源:互联网 | 2023-10-09 20:05
Iamfairlynewtoangularjsandamnotabletofindanydocumentationorexamplesforthis.WhatI
I am fairly new to angularjs
and am not able to find any documentation or examples for this. What I am looking to do is to extend a basic service so that i can use the methods defined under the basic service from other services. So for example say i have a basic service as follows.
对于angularjs来说,我是一个新手,我找不到任何相关的文档或例子。我要做的是扩展一个基本的服务,这样我就可以使用其他服务在基本服务下定义的方法。比如我有一个基本的服务,如下所示。
angular.module('myServices', []).
factory('BasicService', function($http){
var some_arg = 'abcd'
var BasicService = {
method_one: function(arg=some_arg){ /*code for method one*/},
method_two: function(arg=some_arg){ /*code for method two*/},
method_three: function(arg=some_arg){ /*code for method three*/},
});
return BasicService;
}
);
Now i want to define an Extended service that extends from the above BasicService
so that i can use methods defined under the BasicService from my extended service. Maybe something like:
现在,我想定义一个扩展的服务,它从上面的BasicService扩展,这样我就可以使用从我的扩展服务中定义的BasicService定义的方法。也许类似:
factory('ExtendedService', function($http){
var ExtendedService = BasicService();
ExtendedService['method_four'] = function(){/* code for method four */}
return ExtendedService;
}
6 个解决方案