不明白。如果我需要我的结果来做更多的事情,那么不要只输入我的变量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
首先你必须定义一个函数,然后调用它/: –