如何更改过滤器内的$ scope变量

Iva*_*chi 6 angularjs

我需要更改$scope过滤器内的变量.该$scope变量用于ng-show属性,并且信息仅在过滤器中加入,因为我有ng-repeat一些信息并由一些过滤器应用,我需要知道过滤器何时删除所有结果以显示消息...这里是一个例如:(这只是一个想法)

.controller("thing", function() {
   $scope.showText = false;
})

.filter("filterText", function() {
   return function(information) {
     if (information == "") { /* NEED TO CHANGE $scope.showText to true */ }
   }
})
Run Code Online (Sandbox Code Playgroud)

HTML:

<div ng-view="showText"> Some Text here </div>
<div ng-repeat="info in information | filterText"></div>
Run Code Online (Sandbox Code Playgroud)

谢谢.

Jef*_*sen 4

我同意这样的评论,即您可能不想首先更改过滤器中的数据,但如果您真的感到压力很大,您可能可以通过在控制器内定义一个过滤器函数(而不是一个过滤器函数)来实现这一点。实际的角度“过滤器”),然后就这样使用它:

ng-repeat="item in items | filter:myFilter()"

$scope.myFilter = function(item) {
    // access to scope here
}
Run Code Online (Sandbox Code Playgroud)