我正在使用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()});
似乎工作,但似乎不是一個乾淨的解決方案。