Currently I have the below structure, no "$apply already in progress"
error thus far (with this structure).
I'm using $timeout,0,true in order to try to ensure that the UI-update
cycles don't overlap.
Does that make sense?
Here's the structure:
angular.module('presence')
.service('usersService', function($timeout) {
this.updateList = function(usersOnline, snapshot) {
// ...
if (!user) {
user = {
// ...
remove: function() {
$_.delFromAry(usersOnline, function(item) {
return
item.id ==
user.id;
});
},
// ...
};
$timeout(
function() {
usersOnline.push(user);
},
0,
true
);
}
user.removalTimer = $timeout(
function() {
user.remove();
},
2000,
true
);
};
});
angular.module('presence')
.controller('ctrl',
function($scope, usersService) {
$scope.usersOnline = [];
function setUserAry(snapshot) {
usersService.updateList($scope.usersOnline, snapshot);
}
// Can fire at any time, async.
onlineStatusData.on('child_added', setUserAry);
}
);
Tobi
--
http://tobireif.com