I have a list with several data ( $scope.messages
), but only some data interest me. After loading this list I make a foreach
and get only the data that interest me and give push
to a new list. This way:
angular.forEach($scope.messages, function(msgBD) {
if((msgBD.user == $scope.usuario && msgBD.destino == destino) || (msgBD.user == destino && msgBD.destino == $scope.usuario )){
$scope.msgs.push(msgBD);
}
});
$scope.messages = $scope.msgs;
However in the view my ng-repeat
does not update itself
<ul class="media-list" ng-repeat="message in messages track by $index">
{{message.text}}
</ul>
When I use $scope.$apply
before the push works perfectly:
$scope.$apply(function(){
$scope.msgs.push(msgBD);
});
But of this error in the console:
"Error: [$ rootScope: inprog] link $ rootScope / inprog? p0 =% 24apply
Is there any way to solve this problem? Or treat this error?
UPDATE I created a Fiddle to better exemplify my problem.
This is the problem The message in the list only "Updates" when I click again on the user I sent the message to.
Fiddle
: link
Update 2
Chat example working perfectly after solution presented by @oOAkiraOo link
NOTE: If many users are online, just click clear users.