本文介绍了OOP类的角度服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论如何,我的认为的这些都是空中接力班,我是新来这一点。我试图转移别人写的成角服务一些复杂的东西,我似乎无法得到正确的语法。我有这样的事情:
Anyway I think these are oop classes, I'm new to this. I'm trying to move some complex stuff written by someone else into an Angular service and I can't seem to get the syntax right. I have something like this:
angular.module('myApp')
.service('myService', function () {
var service = this;
this.Util = {
extend: function (blah) {
//blah blahh
return blah
},
create: Object.create || (function (blah) {
//blah blah
return blah
})(),
//more blah blah
};
var something = this.Util.create(blah);
});
我希望这是足够的细节,告诉我在做什么错。它告诉我它无法读取财产'的未定义创建。
I hope that's enough detail to tell what I'm doing wrong. It's telling me it 'Cannot read property 'create' of undefined'.
推荐答案
我会尽量给你一个办法做到这一点:
i will try to give a you a way to do it :
服务
angular.module('myApp').service('Util', [function () {
this.extend = function (blah) {
//blah blahh
return blah
};
this.create: function (blah) {
//blah blah
return blah
},
// should write new methods like this.myMethod
}]);
控制器
angular.module('myApp').controller('myCtrl',[
'Util',
function(UtilSvc) {
var something = UtilSvc.create(); // call your service method
}
]);
这篇关于OOP类的角度服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!