[英]How to fetch data from an object using ngfor in angular
I am trying to access price data inside space array which is inside an Object我正在尝试访问 Object 内的空间数组内的价格数据
this.apartmentService.customPackage(this.uid, this.client, this.access_token).subscribe(user => {
this.packages = user;
console.log(this.packages);
})
}
Template File模板文件
<ng-container *ngFor="let item of packages?.essential_interiors.space.name | keyvalue">
<li class="list-group-item">{{item.value}}</li>
</ng-container>
But i am not able to fetch particular space from this reponse但我无法从这个响应中获取特定空间
any lead would be helpful任何线索都会有所帮助
You should to delete name from the foreach like:您应该从 foreach 中删除名称,例如:
<ng-container *ngFor="let item of packages?.essential_interiors.space">
<li class="list-group-item">{{item.price}}</li>
</ng-container>
KeyValuePipe
transforms only Object or Map into an array of key value pairs. KeyValuePipe
仅将 Object 或 Map 转换为键值对数组。
But in your case, you have an array space
.但在你的情况下,你有一个数组
space
。
You simply should itarate *ngFor="let item of packages?.essential_interiors.space"
你应该简单地 itarate
*ngFor="let item of packages?.essential_interiors.space"
<ng-container *ngFor="let item of packages?.essential_interiors.space">
<li class="list-group-item">{{item.price}}</li>
</ng-container>
WORKING EXAMPLE:工作示例:
https://stackblitz.com/edit/angular-vfwcio?file=src/app/app.component.html https://stackblitz.com/edit/angular-vfwcio?file=src/app/app.component.html
Check below thing and let me know what is output display please检查下面的东西,让我知道什么是 output 显示器
<ul>
<li *ngFor="let item of packages; let i = index">
{{i}} {{item}}
</li>
</ul>
Did you try like this item.essential_interiors.space.name directly in your li tag.您是否直接在您的 li 标签中尝试过喜欢这个 item.essential_interiors.space.name 。
<ng-container *ngFor="let item of packages">
<li class="list-group-item">{{item.essential_interiors.space.name}}</li>
</ng-container>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.