I'm trying to reload an image from my webserver every n seconds. The code below drags the new picture, but it doesn't replace the old one in the client. Where is my mistake?
<div ng-app="refresh-div" ng-controller="refresh_control">
<img ng-src="{{imageUrl}}" />
</div>
<script>
var app = angular.module('refresh-div', [])
.controller('refresh_control', function ($scope, $http, $timeout) {
$scope.imageURL = 'assets/now.png?_ts=' + new Date().getTime();
$scope.getData = function () {
$http.get($scope.imageURL, {
cache: false
}).success(function (data, status, headers, config) {
$scope.image = data;
$scope.imageUrl = "http://mywebsite/assets/now.png";
});
};
$scope.intervalFunction = function () {
$timeout(function () {
$scope.getData();
$scope.intervalFunction();
}, 1500)
};
$scope.intervalFunction();
});
</script>
thenfunction to update data, or b) wrap either your timeout or success data switch inside$scope.$apply(function() { $scope.imageUrl = '..'; }). Usually this is reserved for when something leaves the angular scope, and maybe that's what happens when timeouts are used for async methods.$scope.imageused for, if anything?