我需要在从HTTP POST请求中获取数据后调用一个方法。
服务:request.service.TS
get_categories(number){
this.http.post( url, body, {headers: headers, withCredentials:true})
.subscribe(
response => {
this.total = response.json();
}, error => {
}
);
}
组件:categories.TS
search_categories() {
this.get_categories(1);
//I need to call a Method here after get the data from response.json() !! e.g.: send_catagories();
}
只有当我更改为:
service: request.service.TS
get_categories(number){
this.http.post( url, body, {headers: headers, withCredentials:true})
.subscribe(
response => {
this.total = response.json();
this.send_catagories(); //here works fine
}, error => {
}
);
}
但我需要在调用this.get_categories(1);
后在组件内部调用send_catagories()
方法,就像这样:
组件:categories.TS
search_categories() {
this.get_categories(1);
this.send_catagories(response);
}
我做错了什么?
send_categories()
方法是否也使用了 Observable?如果是的话,你需要使用.mergeMap()
操作符将get_categories()
返回的 Observable 与send_categories()
中的 Observable 进行链式操作。如果需要语法方面的帮助,请告诉我。 - AngularChef