我有一个带有两个过滤器的 ng-repeat。当我通过按钮更新一个“uniqueFilter”时,列表不会使用我的新过滤器进行更新。这是 HTML
<div ng-controller="FooterController" class="bar bar-footer">
<button class="button button-clear" ng-click="switchViewType('LOCATIONS')">Locations</button>
<button class="button button-clear" ng-click="switchViewType('DEPARTMENTS')">Right</button>
<button class="button button-clear" ng-click="switchViewType('CENTERS')">update</button>
</div>
<div class="list list-inset has-subheader-sbm">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" ng-model="query" placeholder="Search">
</label>
</div>
<ion-content ng-controller="ListController" class="has-subheader-search-sbm">
<ion-list>
<a class='item item-icon-right' ng-repeat="item in directory | filter : type=uniqueFilter | filter : query" href="tel:{{item.phone}}">
{{item.label1}}<br>
{{item.label2}}
<i class="icon ion-ios-information-outline"></i>
</a>
</ion-list>
</ion-content>
这是我的 app.js 代码
appCtrl.controller('ListController', function($scope, $http) {
var url = 'https://server/Ataglanceservice.svc/getDAAG';
$http.get(url).then(function(resp) {
// For JSON responses, resp.data contains the result
$scope.data = resp.data
$scope.directory = angular.fromJson($scope.data);
}, function(err) {
console.error('ERR', err);
})
$scope.uniqueFilter = 'DEPARTMENTS';
//$scope.varView = 'LOCATIONS';
});
appCtrl.controller("FooterController", function($scope, $localStorage) {
$scope.switchViewType = function($viewType) {
$scope.uniqueFilter = $viewType;
}
});
谁能告诉我为什么我的过滤列表没有更新?
谢谢。
最佳答案
每个 Controller 中的作用域都不同,每个 $scope.uniqueFilter 指向不同的位置。解决此问题的一个简单方法是合并 Controller ,并在可能的情况下仅使用 1 个 Controller ,或者使用 Angular 服务 ( https://docs.angularjs.org/guide/services ),将变量作为服务的一部分,以便可以在不同的 Controller 之间使用。 p>
关于javascript - AngularJS 动态过滤未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32213254/