I have a loop for products, which is working perfectly.
<div ng-repeat="result in results track by result.uid">
<img ng-src="{{ result.img';" alt="{{ result.name }}"
title="{{ result.name }}" />
<p><span class="money">£{{ result.price | number:2 }}</span></p>
<p class="product-title">
<a ng-href="{{ result.url }}">{{ result.name }}</a>
</p>
</div>
Within the loop, there's an object which has JSON data.
{{result.colours}}
This contains the following:
[
{
"id":866337128495,
"title":"Product Title",
"handle":"product-url",
"image":"/img.jpg",
"sku":"SKU001",
"name":"Product Name",
"type":"one_color",
"data":"#000000"
},
{
"id":866337128496,
"title":"Product Title2",
"handle":"product-url2",
"image":"/img2.jpg",
"sku":"SKU002",
"name":"Product Name 2",
"type":"one_color",
"data":"#000000"
}
]
I need to loop through this, and have tried:
<div ng-init="swatches=result.colours">
<div ng-if="swatches">
<div ng-repeat="(key,value) in swatches">
{{key}}:{{value}}
</div>
</div>
</div>
This simply returns:
0: [
{
"id":866337128495,
"title":"Product Title",
"handle":"product-url",
"image":"/img.jpg",
"sku":"SKU001",
"name":"Product Name",
"type":"one_color",
"data":"#000000"
},
{
"id":866337128496,
"title":"Product Title2",
"handle":"product-url2",
"image":"/img2.jpg",
"sku":"SKU002",
"name":"Product Name 2",
"type":"one_color",
"data":"#000000"
}
]
I'm new to Angular, however I've researched a lot of different possibilities to do this but have fallen short. Any ideas would be much welcomed!
ng-ifis the culprit here, try change theng-iftong-show. Reason behind is theng-ifwill create a child scope and yourswatcheswill not working.