2015-08-18 27 views
0

我试图显示我的JSON输出到我的视图的帖子,但我得到一个错误。

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: []

我做了一些研究,它看起来像我循环的循环导致角我的浏览器“撞车”了。但是我在代码中找不到错误。

这是我的家庭状态,如果我注释掉这一行return post.getAll();,我显然没有看到错误。

.state('home', { 
    url: '/home', 
    templateUrl: '../assets/angular-app/templates/_home.html.haml', 
    controller: 'mainCtrl', 
    resolve: { 
    postPromise: ['posts', function(posts){ 
     return posts.getAll(); 
    }] 
    } 
}) 

getAll();在我的服务中引用。

.factory('posts', [ 
    '$http', 
    function(){ 
     var o = { 
     }; 
     return o; 

     o.getAll = function() { 
     return $http.get('/posts.json').success(function(data){ 
      angular.copy(data, o.posts); 
     }); 
     }; 
    } 
]) 

所以我认为错误应该在这些代码之一,任何想法?

我有2个模板,包括我,

posts.html.haml

%div{"ng-repeat" => "comment in post.comments | orderBy:'-upvotes'"} 
    {{comment.upvotes}} - by {{comment.author}} 
    %span{:style => "font-size:20px; margin-left:10px;"} 
    {{comment.body}} 

%form{"ng-submit" => "addComment()"} 
    %h3 Add a new comment 
    .form-group 
    %input.form-control{"ng-model" => "body", :placeholder => "Comment", :type => "text"} 
    %button.btn.btn-primary{:type => "submit"} Post 

%a{"ui-sref" => "home"} Home 

而且home.html.haml

%form{"ng-submit" => "addPost()"} 
    %input{:type => "text", "ng-model" => "title"} 
    %button{:type => "submit"} Post 

%h1 
    Posts 
%div{"ng-repeat" => "post in posts | orderBy: '-upvotes'"} 
    {{ post.title }} - upvotes: {{ post.upvotes }} 
    %a{:href => "#/posts/{{$index}}"} Comments 

我评论说这两个文件,而且还错误是给出的。

+1

您的视图中可能有错误。像嵌套的ng-repeat或者导致摘要循环重复10次以上的东西。 你可以添加模板的代码? – MoLow

+0

@MoLow我已经添加了模板代码,但这不是问题。当我注释掉所有的haml代码时,它仍然会给出错误。 –

回答

0

经过一番研究,我发现return o;这个服务应该在文件底部。

相关问题