简体   繁体   English

属性“ json”在“对象”类型中不存在

[英]Property 'json' does not exist on type 'Object' in angular

I have just updated my angular app to angular 7 and using http client. 我刚刚将我的angular应用程序更新为angular 7,并使用了http客户端。 The moment I have updated to httpClient I am getting the following error 更新到httpClient的那一刻,我收到以下错误

Property 'json' does not exist on type 'Object' at line let act = data.json().find(x => x.ActivityId == activityId); 在行let act = data.json()。find(x => x.ActivityId == activityId)的行上,类型'Object'不存在属性'json';

I presume the reason being get returns the type Observable. 我认为被获取的原因返回的类型是Observable。 Do I need to change the return type of the method to return a response. 我是否需要更改方法的返回类型以返回响应。 I was under the impression that httpclient returns json by default 我的印象是httpclient默认返回json

this.documentService.getDocuments(mgrStrategyId, docId, activityTypeId)
  .subscribe(data => {
    let act = data.json().find(x => x.ActivityId == activityId);
    if (act == null) {
      isOwner = false;
      InteractionDate = new Date();
    }
    else {
      isOwner = act.IsOwner;
      InteractionDate = act.InteractionDate;
    }
    this.init(mgrStrategyId, firmId, activityId, activityName, isOwner, new Date(InteractionDate), false);
  },
    err => {
      this.Error = 'An error has occurred. Please contact BSG';
    },
    () => {
    })



getDocuments(strategyId: number, documentTypeId: number, activityTypeId: number) {
  let pars = new HttpParams();
  if (strategyId != null)
    pars.set('strategyId', strategyId.toString());
  pars.set('documentTypeId', documentTypeId.toString());
  pars.set('activityTypeId', activityTypeId.toString());
  return this.http.get(this.config.api.getDocuments, { params: pars, withCredentials: true });
}

You don't need to call data.json() in Angular 7 HttpClient ( getting-json-data ): 您无需在Angular 7 HttpClientget-json-data )中调用data.json() ):

 .subscribe(data => {
   let act = data.find(x => x.ActivityId == activityId);
   if (act == null) {
    isOwner = false;
    InteractionDate = new Date();
   }
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM