angularjs - Update Mail Count With Angular -
i trying continuously keep updated count of unread messages. angular code have right doesn't replace current count puts new count next it. on , on again. not if using right method this. appreciated.
'use strict'; angular.module('chatapp') .controller('viewedctrl', function($scope, mail, $interval) { var countloaded = function(count) { $scope.count = count; } var handleerrors = function(response) { console.error(response); } var getupdates = function() { return mail.viewed().then(updatesloaded); } var updatesloaded = function(updates) { $scope.count = $scope.count.concat(updates); } $interval(getupdates, 3000); mail.count() .then(countloaded) .then(getupdates) .catch(handleerrors); }); i have {{count}} in view.
welcome stackoverflow! problem in updatesloaded function. using concat function append updates $scope.count variable.
for example:
// string var somestring = 'hello' somestring = somestring.concat(' world!') // 'hello world!' // array var somearray = [1, 2] somearray = somearray.concat([3]) // [1, 2, 3] what want assign $scope.count whatever current count of unread mail.
so depending on value of updates is, work:
var updatesloaded = function (updates) { $scope.count = updates )
Comments
Post a Comment