试图隐藏ng-repeat的第一和第三列

时间:2017-05-19 10:40:51

标签: html angularjs html-table angularjs-ng-repeat

我有一个表使用ng重复列,现在我想隐藏第一列和第三列。有谁知道我会怎么做?

ng-hide="$first&&$third" 

没有工作

这就是它的外观:

<th role="columnheader" ng-repeat="column in tableColumns" ng-hide="$first&&$third" ng-if="column.visible">{{column.displayName}}</th>

3 个答案:

答案 0 :(得分:0)

试试这个

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
	<script type="text/javascript">
		var myapp = angular.module('myapp', []);
		myapp.controller('FirstCtrl', function($scope) {
			$scope.collectioninfo = [{
				"CompID": "0001388D",
				"CompName": "INFY",
				"CompLoc": "IN"
			},
			{
				"CompID": "0001388D2",
				"CompName": "TCS",
				"CompLoc": "IN"
			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			},
			{
				"CompID": "0001388D23",
				"CompName": "WIPRO",
				"CompLoc": "IN"

			}
			]

			$scope.checkIfHidden = function(index) {
				if (index == 0 || index == 2) {
					return true;
				}else{
					return false;
				}

			};
		});
	</script>
</head>
<body>
	<div ng-app="myapp" ng-controller="FirstCtrl">
		<div ng-repeat="val in collectioninfo track by $index">
			index {{$index}}:  <span ng-hide="checkIfHidden($index)">{{val.CompID}}</span> 
		</div>
	</div>
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用计数器。并检查计数器的值以添加列。请参阅此下面的代码作为参考。

<tr ng-repeat="obj in OrderList">
     <td>{{obj.ID}}</td>
     <td>{{obj.Name}}</td>
     <td ng-if="((++$index != 3)||($index != 1))">
         <i>Delete</i>
     </td>
</tr>

希望这有帮助。

答案 2 :(得分:0)

这隐藏了数组中第一个和第三个位置的任何值

<span ng-hide="($index + 1) == ($first || ($first + 3))">{{val.CompID}}</span>