【发布时间】:2020-04-14 05:45:09
【问题描述】:
“对象”类型可以分配给极少数其他类型。您的意思是改用 'any' 类型吗?
res : any[];
constructor(http: HttpClient) {
http.get('http://jsonplaceholder.typicode.com/posts')
.subscribe(response => {
this.res = response;
});
【问题讨论】:
-
如果有任何[],你为什么还要设置一个类型?这意味着什么......
-
顺便说一句,在构造函数中使用 http 的东西是一个非常糟糕的主意。改为
ngOnInit -
分配 this.res = response 时出错
标签: angular httpclient angular-httpclient