[英]Property 'Object' does not exist on type 'FoldersPage'
With the help of *ngFor
directive, I'm iterating through an array of objects and trying to render first key of each object on the layout.在
*ngFor
指令的帮助下,我遍历对象数组并尝试在布局上呈现每个对象的第一个键。 But I'm facing this error:但我正面临这个错误:
Property 'Object' does not exist on type 'FoldersPage'
类型“FoldersPage”上不存在属性“Object”
Here's my code:这是我的代码:
<ion-list>
<ion-item *ngFor="let folder of folders" (click)="open(folder)">
<ion-label>
<h1>{{ Object.keys(folder)[0] }}</h1> // Error line
<p>31 tasks</p>
</ion-label>
<ion-icon (click)="edit(folder);$event.stopPropagation()" slot="end" name="pencil"></ion-icon>
<ion-icon (click)="delete(folder);$event.stopPropagation()" slot="end" name="trash"></ion-icon>
</ion-item>
</ion-list>
How to solve this error?如何解决这个错误? Or if it's not possible this way than is there any other better alternative approach?
或者,如果这种方式不可能,那么还有其他更好的替代方法吗?
Thanks.谢谢。
Inorder to use Object.keys(folder)[0]
in template, call a function from template and from that function defenition return the keys.为了在模板中使用
Object.keys(folder)[0]
,从模板调用一个函数,并从该函数定义返回键。
In Template在模板中
{{ getKeys(folder)[0] }}
And in component.ts在 component.ts
getKeys(obj) {
return Object.keys(obj);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.