【发布时间】:2019-01-09 16:08:44
【问题描述】:
我在 Angular 6 中收到以下函数的以下错误
public getList() {
return this.http.get(environment.serverUrl +'/vmsdata/v1/tftoport/customer/1001')
.toPromise()
.then(response => response.json()
.then(json => {
console.log('data', json.items);
return json.items;
});
}
对于.then(response => response.json() 行,错误是
[ts] Property 'json' does not exist on type 'Object'.
对于.then(json => { 行,错误为[ts] Parameter 'json' implicitly has an 'any' type.
【问题讨论】:
-
您的代码中至少缺少一个右括号
)。 -
this.http是Http或HttpClient的实例吗?您可以通过将json => ...更改为(json: any) => ...来消除第二个错误,或者您可以在 tsconfig.json 中禁用 noImplicityAny -
在 Angular 6 中,旧的、已弃用的
Http类不再存在,因此它必然是HttpClient;默认情况下将检索到的数据转换为 json。所以你不需要.then(response => response.json())行
标签: javascript json angular angular6