【发布时间】:2017-03-06 17:30:13
【问题描述】:
我编写了以下代码,它运行:
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('editor', {
resolve: {
init: ['codeService', function (codeService) {
return codeService.init()
}]
}
...
})
app.service('codeService', ['$http', function ($http) {
this.init = function () {
initFolder()
...
}
var initFolder = function () {
// the code inside does not mention "this"
...
}
}
我意识到,要在reslove 中使用codeService.init,我需要用this 定义init,而initFolder 可以定义为私有方法。但是,以下定义不起作用:
this.init = function () {
this.initFolder()
...
}
this.initFolder = function () {
// the code inside does not mention "this"
...
}
有谁知道为什么我不能用this 定义initFolder?
【问题讨论】:
-
请检查我的回答是否能解决您的疑问
标签: javascript oop this angular-services