I have a little problem where i cannot update the Poller.msgdata in the view each time the poller timeouts.
So what i am trying to do is receive Poller.msgdata and Poller.newdata TRUE or FALSE on condition from the Service, and then output this dynamically inside {{inbox}}. However $scope.inbox comes as empty since on first retrieval the data is Undefined, this not being the problem. Its the fact that the msgdata and newdata do NOT update when Poller timeouts.
{{inbox}} should be TRUE or FALSE and UPDATE accordingly each time. If you need more details please let me know.
app.controller("taskbarController", ['$scope', 'authData', '$location', 'projectsModal', 'sendMessageModal', 'Poller',
function ($scope, authData, $location, projectsModal, sendMessageModal, Poller) {
$scope.inbox = Poller.msgdata;
$scope.project = Poller.newdata;
$scope.projects = Poller.projects;
$scope.messages = Poller.messages;
}]);
Here is the Poller that updates the msgdata and newdata:
app.factory('Poller', Poller);
Poller.$inject = ['$http', '$timeout'];
function Poller($http, $timeout) {
var projectcache = { response: [], calls: 0 };
var msgcache = { response: [], calls: 0 };
var newdata;
var msgdata;
var poller = function () {
$timeout(poller, 5000);
$http.get('http://localhost/app/controllers/php/getProjects.php')
.then(function(r) {
if (r.data.projects.length > projectcache.response.length) {
newdata = true;
projectcolor = 'green';
angular.copy(r.data.projects, projectcache.response);
} else {
newdata = false;
projectcolor = 'green';
};
});
$http.get('http://localhost/app/controllers/php/getMessages.php')
.then(function(m) {
if (m.data.messages.length > msgcache.response.length) {
msgdata = true;
msgcolor = 'green';
angular.copy(m.data.messages, msgcache.response);
} else {
msgdata = false;
msgcolor = 'green';
};
});
};
poller();
return {
projects: projectcache.response,
messages: msgcache.response,
newdata: newdata,
msgdata: msgdata
};
};
And finally i display inside the partial as:
{{inbox}}