我在使用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
不火。我在這裏做錯了什麼?