Below is an example of a Backbone post model:
var Post = Backbone.AssociatedModel.extend({
urlRoot: ApiService.resolveRESTUrl('posts'),
defaults: {
age : 0,
fname : "",
lname : "",
manager : null
},
relations:[
{
type:Backbone.One,
key:'User',
relatedModel: function(){ return $injector.get('UserModel') },
collectionType: function(){return $injector.get('UserModel').Collection; }
},
{
type:Backbone.Many,
key:'Last3Comments',
relatedModel:function(){ return $injector.get('CommentModel') },
collectionType:function(){ return $injector.get('CommentModel').Collection },
}
],
getTimeAgo:function() {},
getPicture:function(size){
return this.get('picture_url') ?
ApiService.getImageResizeUrl(this.get('picture_url'),'w'+size+'xh'+size) :
null;
},
});
While loading posts, if any library using Angular watcher in the post array (binded with "="), I encounter the following error:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: []
Additionally,
RangeError: Maximum call stack size exceeded at Array.toString (native)
I am monitoring posts in this manner:
$scope.posts=[];
$scope.$watch('posts', function(model) {
console.log($scope.posts, model);
},true);
$scope.loadPosts=function(){
if($scope.loading || $scope.disabled) return;
$scope.loading=true;
ApiService.request("posts/home",{page:$scope.page,limit:10}).success(function(data){
$scope.loading=false;
$scope.page++;
if(data.error){
alert('Error');
} else {
if(data.data.posts.length==0)
$scope.disabled=true;
$.each(data.data.posts,function(i,e){
var post=new PostModel(e);
$scope.posts.push(post);
});
}
}).error(function(){
alert('Error');
$scope.loading=false;
});
};
Any thoughts on how to resolve these errors?