admin管理员组文章数量:1312866
this is a follow up question to this topic: Calling a function in AngularJS service from the same service?
I realized too late I should open a new question instead asking it there (sorry for that)
I want to do the following: calling a function within a service function with the additional difficulty the call is within $watchCollection. It looks something like this:
return {
myFunc1: function(param) {
},
myFunc2: function(scope,param) {
scope.$watchCollection(param,function(v) {
return foo + this.myFunc1(param)// do some stuff with the first function
}
}
}
Because of function(v) { you are now in another function within the function and this
is no longer the service but the window
.
how can I get access to this myFunc1 within the myFunc2 $watchCollection parameter function?
thanks in advance
this is a follow up question to this topic: Calling a function in AngularJS service from the same service?
I realized too late I should open a new question instead asking it there (sorry for that)
I want to do the following: calling a function within a service function with the additional difficulty the call is within $watchCollection. It looks something like this:
return {
myFunc1: function(param) {
},
myFunc2: function(scope,param) {
scope.$watchCollection(param,function(v) {
return foo + this.myFunc1(param)// do some stuff with the first function
}
}
}
Because of function(v) { you are now in another function within the function and this
is no longer the service but the window
.
how can I get access to this myFunc1 within the myFunc2 $watchCollection parameter function?
thanks in advance
Share Improve this question edited May 23, 2017 at 12:17 CommunityBot 11 silver badge asked Nov 18, 2013 at 16:30 SleeneeSleenee 5941 gold badge8 silver badges21 bronze badges1 Answer
Reset to default 9You can save the this
in another variable (usually called self
or that
) and use it to access myFunc1
.
myFunc1: function(param) {
},
myFunc2: function(scope,param) {
var self = this;
scope.$watchCollection(param,function(v) {
return foo + self.myFunc1(param)// do some stuff with the first function
}
}
本文标签:
版权声明:本文标题:javascript - Calling a function in AngularJS service from the same service but within $watchcollection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741904002a2404033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论