Angular ng-repeat过滤器隐藏元素

时间:2016-02-11 09:04:56

标签: angularjs angularjs-filter

我需要public @interface EntityScan的过滤器,它会隐藏元素。 如果ng-repeat成真,我需要在$scope.selectedselect: true

时隐藏元素



visible: false

$scope.selected = false;

$scope.array = [
{name: 'item1', select: true, visible: false},
{name: 'item2', select: true, visible: true},
{name: 'item3', select: false, visible: true},
{name: 'item4', select: true, visible: false},
{name: 'item5', select: false, visible: true},
]




4 个答案:

答案 0 :(得分:3)

在这种情况下,您需要使用filter

jsfiddle中的实例。

var myApp = angular.module("myApp", []);


myApp.controller("myCtrl", function($scope) {
$scope.selected = true;
$scope.myFilter = function(item){
 return $scope.selected && (!item.visible || item.select)
}
$scope.array = [
{name: 'item1', select: true, visible: false},
{name: 'item2', select: true, visible: true},
{name: 'item3', select: false, visible: true},
{name: 'item4', select: true, visible: false},
{name: 'item5', select: false, visible: true},
]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
  <div ng-repeat="item in array|filter:myFilter">
	<div>{{item.name}}</div>
</div>
</body>

答案 1 :(得分:1)

试试这个

<div ng-repeat="item in arrray">
   <div ng-show="selected">
      <div ng-hide="item.visible==false && item.select==true">{{item.name}}</div>
   </div>
</div>

答案 2 :(得分:0)

使用ng-if:

<div ng-if="item.visible && selected && item.select == true">{{item.name}}</div>

答案 3 :(得分:0)

我会推荐这个:

<div ng-repeat="item in array">
    <div ng-hide="selected && (!item.visible || item.select)">{{item.name}}</div>
</div>