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:
angular
.module('app')
.controller('tlmController', function($scope, $http) {
var vm = this;
var data = [];
vm.countTestLines = 0;
vm.loadingComplete = false;
$scope.$watch('vm.loadingComplete', function() {
console.log(data);
console.log(oldVal);
});
$http({
method: 'GET',
url: 'app/server/testlinemonitor/count_testlines.php'
}).then(function successCallback(response) {
vm.countTestLines = parseInt(response.data.count);
downloadInParts(data, 0, vm.countTestLines);
}, function errorCallback(response) {
console.log('error');
});
var downloadInParts = function(data, offset, max) {
if(max < offset) {
vm.loadingComplete = true;
}
$http({
method: 'GET',
url: 'app/server/testlinemonitor/get_testlines.php',
params: { offset: offset }
}).then(function successCallback(response) {
data = data.concat(response.data);
downloadInParts(data, offset + 5, max);
}, function errorCallback(response) {
console.log('error');
});
}
});
Niestety nic sie nie dzieje, tzn kod wykonuje sie jakby od razu a nie po zmianie wartosci zmiennej loadingComplete.