简体   繁体   中英

Property 'json' does not exist on type 'Object' in angular

I have just updated my angular app to angular 7 and using http client. The moment I have updated to httpClient I am getting the following error

Property 'json' does not exist on type 'Object' at line let act = data.json().find(x => x.ActivityId == activityId);

I presume the reason being get returns the type 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

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 ):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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