I have this data in in-memory-data.service.ts:
import {InMemoryDbService} from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const values = [
{
id: 0,
title: 'Calculus',
author: 'John Doe',
date: '2018-05-15',
content: 'Random text',
category: 'Science'
},
{
id: 1,
title: 'Bulbasaur',
author: 'John Doe',
date: '2000-09-14',
content: 'Random text',
category: 'TV shows'
},
{
id: 2,
title: 'Fourier Analysis',
author: 'John Doe',
date: '2014-01-01',
content: 'Random text',
category: 'Science'
}
];
return {values};
}
}
Currently I am displaying the data in one of my components:
<ol class="list-unstyled mb-0">
<li *ngFor="let value of values">{{value.title}}</li>
</ol>
How can I display only category "Science" values?
You can filter it out using filter
of java script which return new array containing your required data , like this :
this.filteredvalues = values.filter(t=>t.category ==='Science');
and then you can iterate over this filtered array
<li *ngFor="let value of filteredvalues ">{{value.title}}</li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With