I am running an Apache Tomcat Web Server with JSP/Servlets. I have a slideshow for my website that works off an html list of elements. I would like to populate this list with some JSON data that I parse after making a call to my Servlet. Normally I would do this in JQuery by changing the inner html of the list and adding each list item but I would like to use Angular JS instead. On a side note, I'm new to Angular JS.
//Note: The list should look like this when all is said and done.
<div data-ng-app="" data-ng-controller="getSlideshowProducts">
<ul class="bxslider" style='width: 100%;'>
<li><img src="http://www.mywebsite.com/product_images/0003500044627.jpg" /><br>$0.75</li>
<li><img src="http://www.mywebsite.com/product_images/0007418226991.jpg" /><br>$3.00</li>
</ul>
</div>
The JSON Data returned by the Servlet looks like this
{"items":
[
{ "quantity":"2",
"price":"0.75",
"name":"Ajax Super Deegreaser Lemon Dish Liquid 14 floz",
"upc":"0003500044627",
"category":"Cleaning Supplies"
},
{
"quantity":"2",
"price":"3.00",
"name":"Softsoap Hand Soap 56 floz",
"upc":"0007418226991",
"category":
"Cleaning Supplies"}
]
}
This is my attempt at creating an app/controller to populate the list, unfortunately, halfway though I realized I couldn't figure out how to change the html/inner html of the list using angular. I have been following the W3 Schools tutorial on the subject but they weren't much help.
//retrieves some random products for the slide show
function getSlideshowProducts($scope,$http) {
var items;
$http({
url: "${pageContext.request.contextPath}/ItemServlet",
method: "GET",
params: {query: "random-item-list", count: "12"}
})
.success(
function(response) {
items = angular.fromJson(response);
}
);
}
Essentially I would like to figure out the proper way of getting each element of the JSON Array and doing something like the following...I'm used to going through the array using jquery and .each but with angular it's a bit confusing.
<li data-ng-repeat = "x in items"><img src="img src="http://www.mywebsite.com/product_images/{{x.upc}}.jpg" /><br>{{x.price}}</li>