我使用TypeScript应用程序中的Angular2中的rxJS使用Observable。我想获取http获取响应数据的副本。在Angular2/Typescript中复制rxJs中的响应数据
服务:
getSizes(sku: number): Observable<SizeList[]> {
let api = this.host + this.routes.sizes + sku;
return this._http.get(api)
.map((response: Response) => <SizeList[]>response.json())
.catch(this.handleError);
}
组件:
getSizes() {
this._productService.getSizes(this.productColour)
.subscribe(
sizes => this.sizes = sizes,
error => this.errorMessage = <any>error);
}
我如何可以采取this.sizes的副本?如果我尝试在我的组件getSizes()的末尾复制副本,则它是未定义的。
你是正确的 - 它现在用你的第一个代码块例如工作。我不知道我可以使用{}来保存多个表达式。谢谢。 –