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
我評論說這兩個文件,而且還錯誤是給出的。
您的視圖中可能有錯誤。像嵌套的ng-repeat或者導致摘要循環重複10次以上的東西。 你可以添加模板的代碼? – MoLow
@MoLow我已經添加了模板代碼,但這不是問題。當我註釋掉所有的haml代碼時,它仍然會給出錯誤。 –