我寫了下面的代碼,它運行定義一個方法:不能與「此」
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
,我需要定義init
與this
,而initFolder
可定義爲私有方法。但是,下面的定義不工作:
this.init = function() {
this.initFolder()
...
}
this.initFolder = function() {
// the code inside does not mention "this"
...
}
有誰知道爲什麼我不能this
定義initFolder
?
請檢查,如果我的答案清除您懷疑 –