【发布时间】:2018-09-20 16:41:35
【问题描述】:
我有一个服务调用并获取服务并获取结果。在使用 type 运行应用程序时,我遇到了错误。
错误是 DataModel 上不存在 ProductTypes 属性。
如果我在下面的行中提供任何工作正常,我将对此进行更改
return this.http.get<any>(SERVICE_URL).pipe(
错误在这一行,类型为:
return res.ProductTypes.map((item:DataModel) => {
服务代码:
fetchProduct(): Observable<DataModel[]> {
return this.http.get<DataModel[]>(SERVICE_URL).pipe(
map(res => {
return res.ProductTypes.map((item:DataModel) => {
return this.Mapper(code, details);
});
}),
catchError(error => this.handleError(error,'error'))
);
}
型号:
import { ProductType } from './product-type-model';
export class DataModel {
code?: string;
ProductTypes?: ProductType;
}
来自服务器的 JSON 响应
{
ProductTypes:[
{
"code":'',
"details":'name'
},
{
"code":'AS',
"details":'Laptop'
}
]
}
【问题讨论】:
-
从服务器你应该得到带有“code”和“ProductTypes”属性的DataModel数组,而不是ProductTypes数组。
标签: angular angular5 angular6 angular2-services rxjs6