我需要调用一个方法后,从HTTP POST请求获取数据角2:如何调用一个函数得到响应后订阅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();
}
只有当我改变工作:
服务: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_catagories()'还使用可观察?如果是,则需要使用'.mergeMap()'运算符将get_categories()中的observable链接到send_categories()中的observable。让我知道你是否需要语法帮助。 – AngularChef
send_catagories()不使用observable,请告诉我语法:return this.http.post(url,body,{headers:headers,withCredentials:true}) .subscribe( response => {this.total_page = response .json(); return this.total_page; },.share() ); } then this.get_category(1).subscribe(response => {this.allFunc(); }); – Louis
明白了。我用正确的语法发布了一个答案。 – AngularChef