Just starting out with angular and facing a problem where I'm unsure of the best approach to setting up this code efficiently.
I have 2 JSON files:
images.json
{
"imageName": "example.jpg",
"imageTags": ["fun","work","utility"]
"productID": ["item1","item3"]
}
products.json
{
"productID": "item1",
"productName": "Staple Gun",
"productURL": "Staple-Gun.htm"
}
I haven't written any actual code yet, as I really want to ensure that my setup is solid before diving in.
My objective is to retrieve images based on tags by using a filter on the initial ng-repeat part. This section is functioning well. However, I also want to link to the products featured in the images. The simplest method I came across was to use ng-repeat with the productID as a filter, but if there are 50 photos each with 2 items, it could potentially result in a lot of repetitions. It seems like this could consume a significant amount of resources. Is this the most effective approach, or is there a better way to address this?
Here's a sample of the code:
<div ng-repeat="photo in photos | filter: 'fun'">
<img ng-src="{{ photo.imageName }}">
<span>Products In This Image</span>
<div ng-repeat="product in products | filter: photo.productID">
<a ng-href="{{ product.productURL }}" title="{{ product.productName }}">{{ product.productName }}</a>
</div>
</div>