如何在角度服务中定义函数,然后在另一个服务的函数中使用函数定义。我实现如下,但它不起作用。我不想返回 ParentService 实例,只是将其构造函数的定义用作 PersonService 的父类。
谢谢你的帮助。
var personModule = angular.module('personModule',['coreModule']).service('personService', function($q, jAjax){
function PersonService($q, jAjax) {
var self = this;
ParentService.call(self, $q, jAjax);
this.name = "person";
};
inherit(ParentService, PersonService);
PersonService.prototype.loadPersonList = function() {
var self = this;
var deferred = self.$q.defer();
ParentService.prototype.loadList.call(self, "meta", function(data){
self.items = data;
deferred.resolve(data);
});
return deferred.promise;
};
return new PersonService($q);
});
var coreModule = angular.module('coreModule',[]).service('commonService', function(jAjax){
var ParentService = function(jAjax) {
};
ParentService.prototype.loadList = function(docType, fn) {
var self = this;
var url = self.name + "/get";
self.jAjax.get(url).success(function(data) {
if (fn !== undefined) {
fn.call(this, data);
}
});
};
return ParentService;
});