我在使用helper
函数设置的上下文变量的指令中使用ng-repeat
,但该指令并未呈现整个集合。据我所知,它正在渲染在指令postLink
时发现的任何内容,但在收集增长时不会重新呈现。angular-meteor:你是如何看待`helpers`方法的集合?
我试图给指令添加一个$watch
,但它只在加载时触发一次,即使Collection增长。
下面是我从meteor-angular-socially
教程创建了一个示例,请参阅:https://github.com/Urigo/meteor-angular-socially/tree/step_14
文件:client/parties/parties-list/parties-list.component.js
angular.module('socially').directive('partiesList', function() {
return {
restrict: 'E',
templateUrl: 'client/parties/parties-list/parties-list.html',
controllerAs: 'partiesList',
controller: function ($scope, $reactive) {
$reactive(this).attach($scope);
window.vm = vm = this;
$scope.$watch(vm.parties, function(newV, oldV) {
// this $watch fires once when the controller is loaded, but never again
// but vm.parties is updated when new parties are added
return console.warn('vm.parties.count=' + (newV != null ? newV.length : void 0));
});
...
this.helpers({
parties:() => {
return Parties.find({}, { sort : this.getReactively('sort') });
},
users:() => {
return Meteor.users.find({});
},
partiesCount:() => {
return Counts.get('numberOfParties');
}
});
集合时被更新的$scope.$watch
不火。我在这里做错了什么?