我刚刚将我的angular应用程序更新为angular 7,并使用了http客户端。更新到httpClient的那一刻,我收到以下错误
在行let act =的'Object'类型上不存在属性'json' data.json()。find(x => x.ActivityId == activityId);
我认为被获取的原因返回了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 });
}
答案 0 :(得分:1)
您无需在Angular 7 data.json()
(getting-json-data)中调用HttpClient
:
.subscribe(data => {
let act = data.find(x => x.ActivityId == activityId);
if (act == null) {
isOwner = false;
InteractionDate = new Date();
}
...