[英]Infinite digest loop errors with Angular-Meteor, PublishComposite and Collection-Helpers
我试图在这两个包的帮助下获得角度流星的一些相关数据:
Meteor-Collection-Helpers: https : //github.com/dburles/meteor-collection-helpers Meteor-Publish-Composite: https : //github.com/englue/meteor-publish-composite
我的设置如下:
模型/ groups.js
Groups = new Mongo.Collection("groups");
Groups.helpers({
usersByScore: function () {
return Meteor.users.find({_id: {$in: this.users}}, {sort: {score: -1}});
}
});
Groups.allow({
insert: function (userId, group) {
return Roles.userIsInRole(userId, 'admin');
},
update: function (userId, group, fields, modifier) {
return Roles.userIsInRole(userId, 'admin');
},
remove: function (userId, group) {
return Roles.userIsInRole(userId, 'admin');
}
});
服务器/ groups.js
Meteor.publishComposite("groupsWithUsers", function () {
return {
find: function() {
if (Roles.userIsInRole(this.userId, 'admin')) {
return Groups.find({});
} else {
return Groups.find({users: { $elemMatch: { $eq: this.userId}}});
}
},
children: [
{
find: function(group) {
return Meteor.users.find({_id: {$in: (group.users) ? group.users : []}});
}
}
]
};
});
客户机/匹配/控制器/ scores.ng.js
angular.module('tippo').controller('ScoresController', ['$scope',
function($scope){
$scope.groups = Groups.find().fetch();
}
]);
客户端/火柴/视图/ scores.ng.html
<div ng-controller="ScoresController">
<md-content class="md-padding">
<md-tabs md-dynamic-height md-border-bottom>
<md-tab label="{{ group.name }}" ng-repeat="group in groups">
<md-content class="md-padding">
<md-list>
<md-list-item class="md-3-line" ng-repeat="user in group.usersByScore()">
<span>({{ user.score }})</span>
</md-list-item>
<md-divider></md-divider>
</md-list>
</md-content>
</md-tab>
</md-tabs>
</md-content>
</div>
客户机/ routes.js
angular.module('tippo').config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
function($urlRouterProvider, $stateProvider, $locationProvider){
$locationProvider.html5Mode(true);
$stateProvider.state('scores', {
url: '/scores',
templateUrl: 'client/matches/views/scores.ng.html',
controller: 'ScoresController',
resolve: {
'subscribe': ['$meteor', function($meteor) {
return $meteor.subscribe('groupsWithUsers');
}],
"currentUser": ["$meteor", function($meteor){
return $meteor.requireUser();
}]
}
});
}
]);
发布/订阅部分工作正常,我可以通过控制台获取所有组和相关用户,但只要我在“group.usersByScore()”中添加“user”,我就会收到很多错误:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (angular.js:68)
at Scope.$get.Scope.$digest (angular.js:15723)
at Scope.$get.Scope.$apply (angular.js:15953)
at safeApply (angular-meteor-meteorCollection.js:154)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (angular-meteor-meteorCollection.js:174)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (observe.js:96)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (observe.js:33)
at minimongo.js:373
at _.extend.runTask (fiber_stubs_client.js:42)
at _.extend.flush (fiber_stubs_client.js:70)
Exception in queued task: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:98:12)
at Scope.$get.Scope.$digest (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15753:19)
at Scope.$get.Scope.$apply (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15983:24)
at safeApply (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1173:47)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1193:11)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3862:28)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3799:56)
at http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:415:13
at _.extend.runTask (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:693:11)
at _.extend.flush (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:721:10)
任何帮助赞赏。
它发生的原因是因为每次调用函数时, usersByScore()
返回一个新的对象实例。 因此,摘要周期认为对象不断更新并放弃以避免卡住。
目前卡在同一个问题上,所以我不知道如何修复它(还)。
编辑:相当广泛地研究了这个问题,我必须得出结论,如果没有角度流星的重大改变就无法完成。
我遇到了类似的问题。 在ng-repeat循环中调用集合文档的集合助手会导致摘要循环。
在我的情况下,我收集了许多团队中每个人的人员(人员文档中的团队ID数组)。
在调查问题之后,我得出了与@mpkorstanje类似的结论。 最后,我发现自己在客户端应用程序中实现了角度流星助手,并为此案例抛弃了集合助手。
我的angular-meteor助手实现看起来像这样:
// persistent instance cache
this.teamsMap = [];
this.helpers({
teams() {
const members = People.find({}).fetch();
members.forEach(member => {
this.teamsMap[member._id] = member.teams.map(team => Teams.findOne(team));
});
}
});
并且控制器功能用于访问视图中人员的团队:
getTeams(member) {
return this.teamsMap[member._id];
}
通过这种实现,反应性和视图绑定按照需要工作,我没有消化循环。 不幸的是它有一种hacky的味道。 希望它可以帮助某人作为一种解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.