Witam,

Mam taki oto kod, ktory dziala poprawnie. Doczytuje po pare rekordow bo chce zrobic fajny loader (a to doczytywanie troche trwa) i jak juz wczyta wszystkie rekordy to ustawia zmienna loadingComplete na true:

[JAVASCRIPT] pobierz, plaintext
  1. angular
  2. .module('app')
  3. .controller('tlmController', function($scope, $http) {
  4. var vm = this;
  5. var data = [];
  6. vm.countTestLines = 0;
  7. vm.loadingComplete = false;
  8.  
  9. $scope.$watch('vm.loadingComplete', function() {
  10. console.log(data);
  11. console.log(oldVal);
  12. });
  13.  
  14. $http({
  15. method: 'GET',
  16. url: 'app/server/testlinemonitor/count_testlines.php'
  17. }).then(function successCallback(response) {
  18. vm.countTestLines = parseInt(response.data.count);
  19.  
  20. downloadInParts(data, 0, vm.countTestLines);
  21.  
  22. }, function errorCallback(response) {
  23. console.log('error');
  24. });
  25.  
  26. var downloadInParts = function(data, offset, max) {
  27. if(max < offset) {
  28. vm.loadingComplete = true;
  29. }
  30.  
  31. $http({
  32. method: 'GET',
  33. url: 'app/server/testlinemonitor/get_testlines.php',
  34. params: { offset: offset }
  35. }).then(function successCallback(response) {
  36. data = data.concat(response.data);
  37. downloadInParts(data, offset + 5, max);
  38. }, function errorCallback(response) {
  39. console.log('error');
  40. });
  41.  
  42.  
  43. }
  44.  
  45. });
[JAVASCRIPT] pobierz, plaintext


Niestety nic sie nie dzieje, tzn kod wykonuje sie jakby od razu a nie po zmianie wartosci zmiennej loadingComplete.