簡體   English   中英

屬性“ json”在“對象”類型中不存在

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

我剛剛將我的angular應用程序更新為angular 7,並使用了http客戶端。 更新到httpClient的那一刻,我收到以下錯誤

在行let act = data.json()。find(x => x.ActivityId == activityId)的行上,類型'Object'不存在屬性'json';

我認為被獲取的原因返回的類型是Observable。 我是否需要更改方法的返回類型以返回響應。 我的印象是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 });
}

您無需在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