【发布时间】:2016-12-14 10:11:10
【问题描述】:
我正在使用 ES6 和 babel 开发 Angular 全栈。
在我的控制器中,我有:
$onInit() {
this.$http.get('/api/example')
.then(() => {console.log("task1")})
.then(() => {console.log("task2")})
}
控制台结果是我想要的:
task1
task2
但是当我尝试重构我的代码时:
$onInit() {
this.$http.get('/api/example')
.then(() => {console.log("task1")})
.then(aFunction())
}
aFunction() {
console.log("task2")
}
控制台结果是:
task2
task1
为什么会这样?
Nb:.then(() => {this.aFunction()}); 似乎有效,但似乎不是一个干净的解决方案。
【问题讨论】:
标签: javascript angularjs promise ecmascript-6 es6-promise