【发布时间】:2018-09-24 05:04:21
【问题描述】:
我在 Angular 5 中有一个数据提供者。
export class DataProvider {
location: any;
private locations: any[] = [
{
"name": "restaurant",
"location": "downtown",
"category": "restaurant",
"id": "1"
},
{
"name": "law firm",
"location": "center city",
"category": "office",
"id": "2"
},
{
"name": "public library",
"location": "suburb",
"category": "library",
"id": "3"
} ]
这是我的 HTML 文件。
<div *ngFor="let location of locations">
<h1></h1>
<h2></h2>
</div>
在这种情况下,如何在具有某些属性的数据数组中加载特定对象(项)?
例如,如果我想用"category" :"restaurant" 加载一个对象,我应该如何处理我的 HTML 文件?所以另外两个不应该出现。我只想通过使用这个特定的属性来加载三分之一。
谢谢。
【问题讨论】:
标签: javascript html arrays angular typescript