【发布时间】:2021-02-04 06:31:42
【问题描述】:
我在 Visual Studio 代码中遇到错误 ->
类型“Object”缺少类型“any[]”中的以下属性:length、pop、push、concat 和 26 个以上。ts
我不知道原因,但请检查我的代码:
trainingPlanResponse: any[] = [];
this.service.postToGetData(model).subscribe(
data => {
// this.trainingPlanResponse.push(data);
this.trainingPlanResponse = data; // HERE IS ERROR!!!
},
err => {
console.log(err)
}
)
当我设置为
trainingPlanResponse: any;
这项工作,但我需要在 html 中设置
<div *ngIf="trainingPlanResponse.length > 0">
response
</div>
重要提示:我没有这个的模型接口!
【问题讨论】:
-
试试
this.trainingPlanResponse = data as any[]; -
你能显示 postToGetData 代码吗?
-
是的,这是可行的,但我想知道为什么会出错?发生了什么?可以不用界面设置吗?
-
@VladimirBozhinovski 这并不重要 它是 const modelPost = { id: thisi , name: this.name ...}
-
试试这样的 -> this.trainingPlanResponse = data || []
标签: javascript html angular typescript