是否有类似 q.all 的东西可以解析 angular2 中的所有 http api 请求?
在 angular1 中,我可以做这样的事情:
var promises = [api.getA(),api.getB()];
$q.all(promises).then(function(response){
// response[0] --> A
// response[1] --> B
})
在 angular2 中,http 模块返回 Observable,
api.getA().subscribe(A => {A})
api.getB().subscribe(B => {B})
但我想一起解决A和B,然后做一些事情。
您将需要.forkJoin
运算符
Observable.forkJoin([observable1,observable2])
.subscribe((response) => {
console.log(response[0], response[1]);
});
您可以导入Observable
with;
import {Observable} from 'rxjs/Rx';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)