I have an array of objects, and I want to get the name of the cars with the same id and display their name and year like this:
ferrai 01-02-2000, 10-23-2010
lambo 08-12-2018, 02-02-2012
NOT like this:
ferrai 01-02-2000
ferrai 10-23-2010
lambo 08-12-2018
lambo 02-02-2012
cars = [
[0] : { year: "01-02-2000"
sport:{id: "1111", name: "ferrai"}
}
[1] : { year: "10-23-2010"
sport:{id: "1111", name: "ferrari"}
}
[2] : {year: "08-12-2018"
sport:{id: "2222", name: "lambo"}
}
[3] : {year: "02-02-2012"
sport:{id: "2222", name: "lambo"}
}
]
how would I be able to do this in angular2+? I have tried this code:
.html file
<div *ngFor="let obj of cars">
<div *ngFor="let name of obj.sport">
<div>{{getCars(name)}}</div>
</div>
</div>
.ts file
getCars(obj){
var sport = obj.sport;
var year = obj.year;
//do stuff
}
I appreciate any help!
namevalue first, and maybe theyearsinto an array, then when you iterate through you'll have a nice data structure to work with.