Scenario
In an Angular2 app, I have some code in a component's view parent.component.html
looping through an array of items
and outputting each item
as a new component:
<div class="list-items">
<!-- In the attached image, this is displayed as a coloured card -->
<app-item *ngFor="let item of items" [item]="item"></app-list-slide>
</div>
Each item
has a category
key which is an array of ids (corresponding to the id of each category in a separate list).
// Item JSON
[
{
"id": 1,
"imageUrl": "https://via.placeholder.com/300x150/FF0000/FFFFFF?text=1",
"title": "One",
"categories": [ 1 ]
}
]
// Category JSON
[
{ "id": 1, "title": "Red Cards" },
{ "id": 2, "title": "Blue Cards" }
]
Requirement
The app needs to have a filter, dynamically generated by the categories (I might make this into a separate component):
<div class="items-filter">
<!-- In the attached image, this is displayed as a list of category buttons -->
<div *ngFor="let category of categories">
<a (click)="filterItemsByCategory(category)">{{ category.title }}</a>
</div>
<div class="btn-o">Reset</div>
</div>
When a category item is clicked, only the items corresponding to that category should be shown. Ideally, multiple categories could be clicked, but that can be for later.
All the examples I can find for filters, seem to use text input based filtering, and I'm not really sure where to start with this.
Final product should look like this:
Similar Example
Here is an example of something very similar to what I am trying to do (but the text input box would be replaced with the array of category buttons):
Article: http://www.freakyjolly.com/angular-4-5-typescript-create-filter-list-with-check-boxes-to-select-from-list/
Demo: https://freakyjolly.com/demo/AngularJS/Angular5FilterList/
Question
My question is either, does anyone know of any good working examples of what I am trying to do, or can anyone suggest a good place to start with this?
One option I can think of is to create classes on the component corresponding to the ids of the categories class="category-1 category-2"
but this seems messy.
Another option is using something like Masonary or Isotope, but a lot of the Angular libraries for these seem to be outdated: https://github.com/search?q=angular+masonry
Thanks