I'm modifying the Altair Material Design Template (http://themeforest.net/item/altair-admin-material-design-premium-template/12190654) & have the following Angular JS controller.
I am successfully calling an API & creating variables in the for loop. I want to then write them to $scope.dragulaItems. This seems to work fine in the console log, however the array is not displaying properly on the page.
The html div is as follows:
<div class="uk-grid uk-grid-width-small-1-2 uk-grid-width-medium-1-3 uk-grid-width-large-1-5" data-uk-grid-margin dragula='"first-dragula"' dragula-model='dragulaItems'>
<div ng-repeat="item in dragulaItems">
I am seeing the correct number of returns in the response on the page (20 styled divs), but no content within them.
angular
.module('altairApp',[angularDragula(angular)])
.controller('addResultsCtrl', [
'$scope',
'$rootScope',
'utils',
function ($scope,$rootScope,utils) {
// Search
SessionKey = "YXZmLwmNiT3vTuXwbbQrSY8ibrGhLuWLZag3DCCH2zu7w9dO3b";
$("#addSearch").submit(function(event) {
event.preventDefault();
var searchTerm = $("#addSearch-term").val();
var settings = {
"async": true,
"crossDomain": true,
"url": "https://secure.techfor.com/labsapi/restservice.aspx?command=PRODUCTSEARCH&searchtext="+searchTerm+"&extendedinfo=n&page=1&sessionkey="+SessionKey+"",
"method": "GET",
"headers": {
"cache-control": "no-cache",
}
}
$.ajax(settings).done(function (response) {
//console.log(response);
$("#searchTerm").html(searchTerm);
$scope.dragulaItems = [];
for (i in response.Products) {
var name = response.Products[i].Name;
var imagePath = response.Products[i].ImagePath;
var EAN = response.Products[i].EANBarcode;
var price = response.Products[i].Price;
var offer = response.Products[i].OfferPromotion;
var offerValid = response.Products[i].OfferValidity;
$scope.dragulaItems.push ("{\"Name\": \""+name+"\",\"Price\": \""+price+"\",\"EANBarcode\": \""+EAN+"\",\"ImagePath\": \""+imagePath+"\",\"OfferPromotion\": \""+offer+"\",\"OfferValidity\": \""+offerValid+"\"}");
}
console.log($scope.dragulaItems);
});
});
}
]);
If I manually change the $scope.dragulaItems = []; to say:
$scope.dragulaItems = [
{"Name":"Bob"},
{"Name":"Reggie"}
];
I get a return of 2 items with the Name field correctly displayed. I am confused as clearly the fact that there are 20 items in the array is getting through, but the content within them is not.
for ... in
for iterating through arrays! – Vohuman 20 hours ago