我正在使用ES6和babel的Angular全堆栈。订单承诺在AngularJs中执行
在我的控制,我有:
$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
为什么会发生这种情况?
铌:.then(() => {this.aFunction()});
似乎工作,但似乎不是一个干净的解决方案。