【发布时间】:2021-08-13 10:34:16
【问题描述】:
我有一个对象 'compareJson' 的数组,使用它我在 html 中显示一个列表。我有一个数组'Cars',我需要使用它来比较它的值(1,4..)和'compareJson'的'id'属性,并且需要在点击'复制'按钮时在HTML中显示相同的列表。如果多个对象中存在相同的 id,则应显示所有对象
app.component.html
<button (click)="duplicate()" >Get values </button>
<div *ngFor="let item of compareJson">Item listed - {{item.details}}</div>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
name = 'Angular';
compareJson = [
{
id: '1',
details: 'Photography details'
},
{
id: '1',
details: 'Writing details'
},
{
id: '3',
details: 'Painting Details'
}
];
Cars = [1, 4];
}
【问题讨论】:
标签: angular