Angular 使用多个https请求类型脚本创建数组

Angular 使用多个https请求类型脚本创建数组,angular,typescript,Angular,Typescript,我正在从事angular cli项目,我有一个方法可以评估多个https请求` this.files=this.http.get(“assets/L10n/customer.json”) .map(res=>res.json()) .subscribe(数据=>console.log(数据)); } this.files2=this.http.get(“assets/L10n/customer2.json”) .map(res=>res.json()) .subscribe(数据=>cons

我正在从事angular cli项目,我有一个方法可以评估多个https请求`

this.files=this.http.get(“assets/L10n/customer.json”)
.map(res=>res.json())
.subscribe(数据=>console.log(数据));
} 
this.files2=this.http.get(“assets/L10n/customer2.json”)
.map(res=>res.json())
.subscribe(数据=>console.log(数据));
}
您可以使用:

您可以使用:


谢谢,它起作用了。console我得到了值。但是当我尝试在另一个方法中使用该值时,它给出了UndefinedIn而不是console,我添加了这个。result=data。当我尝试打印这个。result在另一个方法中它说UndefinedYou访问
this.data
?请记住,这些操作是异步的。只有在HTTP调用完成后,您才能获得该值——这是异步的。好吧,我要做的就是让您可以使用。或者将你想要的数据作为回调传递给函数,并在
subscribe
中执行它。谢谢它工作了。console我得到了值。但是当我尝试在另一个方法中使用该值时,它给出了undefined而不是console,我添加了这个。result=data。当我尝试在另一个方法中打印这个。result是undefined you正在访问此.数据?请记住,这些操作是异步的。只有在HTTP调用完成后,您才能获得该值——这是异步的。好吧,我要做的就是让您可以使用。或者将函数作为回调传递到需要数据的位置,并在
subscribe
中执行它。
let first = this.http.get("assets/L10n/customer.json")
    .map(res => res.json());
let second = this.http.get("assets/L10n/customer2.json")
    .map(res => res.json());

Observable.forkJoin(first, second).subscribe(
    (resultArray) => {
        // `resultArray` is a combined array of first and second results
        console.log(resultArray);
    }
)