在ui网格过滤器上的$ watchCollection

时间:2015-08-27 14:09:51

标签: javascript angularjs angular-ui-grid

我正在尝试使用$ watchCollection函数将表(ui网格)与Angular中的另一个视图连接起来。 我需要$ watchCollection来观察表格中的文本框(过滤区域),当识别出更改时,文本会根据过滤器值被削减。

我已经定义了UI网格<div ui-grid="gridOptions" ng-model="query" ui-grid-selection class="grid"></div>,现在我正在尝试$ watch使用$ watchCollection监视表中的整个数组(过滤器):

 $scope.$watchCollection("query", function(newList, oldList) {
       $scope.newList = newList;
       $scope.oldList = oldList;
    });

当我在过滤器中写入时,没有任何变化.. 请看一下plunker,我做错了什么?

1 个答案:

答案 0 :(得分:1)

添加true以在列表中找到任何值更改

$scope.$watchCollection("query", function(newList, oldList) {
   $scope.newList = newList;
   $scope.oldList = oldList;
}, true);