I want to make some changes to my data controller that I get from the server. I gave an example to explain my problem. The recursive update method does not seem to update the value $scope.gdevPiechartArchiveVolume. Can someone tell me why? Is there a way to initiate an update? Thank!
angular.module('socketTestApp')
.controller('MainCtrl', function($scope, Socket) {
Socket.on('gdevAreachart_archiveVolume_update', function(data_) {
selectArchiveData(data_);
});
function selectArchiveData(data) {
var i = 0;
var selectedData;
$scope.update = function() {
_.delay($scope.update, 2000);
if ($scope.pause)
return
i++
$scope.gdevPiechartArchiveVolume = i;
console.log('Updates in $scope.update: ' + $scope.gdevPiechartArchiveVolume);
}
$scope.update();
}
My direcitve (observed variable data " $scope.gdevPiechartArchiveVolume"):
angular.module('socketTestApp')
.directive('gdevAreachart', function() {
var linker = function(scope, element, attr) {
scope.$watch('data', function(newVals, oldVals) {
console.log("Direktive: " + newVals);
return
}, true);
Console output (" Direktive:..." should be printed every time, for example, "Updates in $ scope.update:"):
Direktive: undefined gdevAreachart.js:14
Updates in $scope.update: 1 main.js:127
Direktive: 1 gdevAreachart.js:14 <---- set scope.pause = true ... false to continue
Updates in $scope.update: 2 main.js:127
Updates in $scope.update: 3 main.js:127
Updates in $scope.update: 4 main.js:127
Updates in $scope.update: 5 main.js:127
Updates in $scope.update: 6 main.js:127
Direktive: 6 gdevAreachart.js:14 <---- set scope.pause = true ... false to continue
Updates in $scope.update: 7 main.js:127
Updates in $scope.update: 8 main.js:127
Direktive: 8 gdevAreachart.js:14 <---- set scope.pause = true ... false to continue
Updates in $scope.update: 9 main.js:127
Updates in $scope.update: 10 main.js:127
Direktive: 10 gdevAreachart.js:14 <---- set scope.pause = true ... false to continue
Updates in $scope.update: 11 main.js:127
Updates in $scope.update: 12
Decision:
function selectArchiveData(data) {
var i = 0;
var selectedData;
$scope.update = function() {
if ($scope.pause)
return
i++
$scope.gdevPiechartArchiveVolume = i;
console.log('Updates in $scope.update: ' + $scope.gdevPiechartArchiveVolume);
setTimeout(function() {
$scope.$apply($scope.update());
}, 2000);
}
$scope.update();
}
source
share