I have a URL from where I pick Chuck Norris Jokes. Basically in order to get 100 jokes I hit the URL 100 times and store the result in an array and do an ng-repeat. Pretty straight forward. Problem comes when I execute the same code on google Chrome. It just fetches the data for the first hit and then does not hit the URL and fills the entire array with the first data. I am not able to get why there is two different behavior for the same code. Please help. It works perfectly in firefox but not in google chrome. You can find the code on Fiddle . Try running the same code on Chrome and Firefox and you will notice the difference. Please help.
The code is as follows :-
var app=angular.module('JokeApp',[]);
/**
* Created by roger on 25/2/14.
*/
app.controller('JokeCtrl',['$scope','$http','$q',function($scope,$http,$q){
$scope.pageTitle="JokeApp";
$scope.data={"jokeList":[]};
$scope.services={};
$scope.processing={};
$scope.processBusy=true;
$scope.dataTemplate=function(id,joke,category){
return {
"id":id,
"joke":joke,
"category":category
};
};
$scope.getJoke = function(callback) {
return $http.get("http://api.icndb.com/jokes/random?limitTo=[nerdy]").success(
function(data) {
return callback($scope.dataTemplate(data.value.id,data.value.joke,data.value.categories[0]));
}
);
};
$scope.getJokes = function () {
var prom = [];
for(var i=0;i<10;i++){
prom.push($scope.getJoke(function(value){
$scope.data.jokeList.push(value);
}));
}
$q.all(prom).then(function () {
console.log("DONE!!!");
console.log($scope.data.jokeList);
$scope.processBusy=false;
});
};
$scope.getJokes();
}]);
And HTML Goes Like
<div class="container-fluid" ng-app="JokeApp" ng-controller="JokeCtrl">
<table class="table-responsive" ng-show="!processBusy">
<thead>
<tr>
<th>ID</th>
<th>Joke</th>
<th>Categories</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in data.jokeList">
<td>{{data.id}}</td>
<td>{{data.joke}}</td>
<td>{{data.category}}</td>
</tr>
</tbody>
</table>
</div>
</body>