大佬教程收集整理的这篇文章主要介绍了Angular 2 – 您如何订阅多个变量?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
{ "customerName": "foo","customerAddress": "123 Somewhere","products": [ { "productName": "bar","productnumber": 123 },{ "productName": "baz","productnumber": 456 } ] }
在我的组件中,我订阅了服务以获取填充customerData.
private _getData() { this._myservice .getData() .subscribe( customerData => this.customerData = customerData,error => this.errormessage = error ); }
此代码正常工作.
在JSON转储中,有两个数据“分组”,即客户数据和产品数据,后者在数组中.理想情况下,我想分别填充产品数据.像这样的东西:
.subscribe( customerData => this.customerData = customerData,productData => this.productData = customerData.products error => this.errormessage = error );
这是可能的,如果是这样,我将如何编码订阅?
subscribe( customerData => { this.customerData = customerData; this.productData =customerData.products; },error => this.errormessage = error );
要么
subscribe( function(customerData) { this.customerData = customerData; this.productData =customerData.products; },error => this.errormessage = error );
以上是大佬教程为你收集整理的Angular 2 – 您如何订阅多个变量?全部内容,希望文章能够帮你解决Angular 2 – 您如何订阅多个变量?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。