不明白。如果我需要我的結果來做更多的事情,那麼不要只輸入我的變量heros。我想調用成功或完成的另一個功能,但我不能。爲什麼是這樣,應該怎麼做?我有另一個變量需要獲取從響應返回的相同數據(它的副本),但是我只能在獲取數據後才能創建副本。angular 2 http.get訂閱:如何在服務完成時調用另一個函數?
this.myService.getHeroes()
.subscribe(
function(response) {
response => this.heros = response;
},
function(error) {
console.log("Error happened" + error)
},
function() {
console.log("the subscription is completed");
}
);
首先你的語法是錯誤的,不會transpile。你需要'(response)=> this.heros = response;'和** not **'function'和箭頭函數的組合。 – Igor
10x我檢查它,但仍然是同一個問題。就像我不能從成功/錯誤/完整功能內調用任何其他函數 – AngularOne
首先你必須定義一個函數,然後調用它/: –