I have written the following code, which runs:
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"
...
}
}
I realise that, to use codeService.init
in reslove
, I need to define init
with this
, while initFolder
can be defined as private method. However, the following definition does not work:
this.init = function () {
this.initFolder()
...
}
this.initFolder = function () {
// the code inside does not mention "this"
...
}
Does anyone know why I could not define initFolder
with this
?