I am trying to iterate through an array of usernames and add the resulting JSONP requests to an array that can be displayed using AngularJS. As follows:
HTML SECTION
<div id = "displayUL" ng-controller="userController">
<ul>
<li ng-repeat="user in results">{{user.user}}<img ng-src="{{user.logo}}">{{user.etcetera}}</li>
</ul>
</div>
JAVASCRIPT SECTION
var app = angular.module('userAPI', []);
app.controller('userController', function($scope,$http){
//Our user name array
$scope.inputUsers= ["userA", "userB", "userC"];
$scope.results = [];
//Loop through each user
$.each($scope.inputUsers,function(key,value){
var currentUserData = {};
currentUserData.user = value;
//URL Request - defined elsewhere with callback for JSONP
var currentURL = streamURL + value + callbackPostfix;
$.getJSON(currentURL, function(data){
//Update temp obj with current data results
currentUserData.found = data.found
currentUserData.logo = data.logo;
...
currentUserData.ecetera = data.ecetera;
//Update results array with current data obj
$scope.results.push(currentUserData);
});
});
When this runs, the results array is empty. Does the JSONP callback fire before the Angular has a chance to update?