【问题标题】:Type: Property Does not exist on Model in RXJS 6 map with angular 6类型:属性在 RXJS 6 地图中的模型上不存在,角度为 6
【发布时间】: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


【解决方案1】:

那是因为你的 DataModel 与服务器响应对象不同步:

export class DataModel {
  code?: string;
  details?: string;
}

顺便问一下import { ProductType } from './product-type-model';里面有什么

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2019-03-07
    • 2019-06-30
    • 2019-04-11
    • 2018-11-17
    相关资源
    最近更新 更多