view raw
Parshuram Parshuram - 5 months ago 48
Javascript Question

ng-show for multiple value

This is my Table

<table class="table table-bordered table-responsive table-hover add-lineheight table_scroll">
<th ng-hide="hidecolumn == key" ng-repeat="(key, value) in localNew[0]">
<tr ng-repeat="test in localNew">
<td ng-hide="hidecolumn == key" ng-repeat="(key, value) in test">

Here hidecolumn will hide my column which i dont want to show
For eg in my controller

This is my data

$scope.localNew = [{ 'name': 'name1', 'age': 24, "salary": 2500, "s": 5 }, { 'name': 'name2', 'age': 26, "salary": 2600, "s": 5 }];

And this my hide column variable

$scope.hidecolumn = "salary";

This works fine

Now my question is that,i want to hide multiple columns
So my scope variable will be like

$scope.hidecolumn = "name,salary";

So how can i manage this in my html table to hide multiple column ie multiple hide values???If you still dont got my question let me know i will add a plunker.Thanku


You should rather use an array instead of a string :

$scope.hidecolumns = ['name', 'salary'];

and a function to check if the current column should be hide or not :

$scope.shouldHideColumn = function(column) {
  if ($scope.hidecolumns.indexOf(column.salary)) {
    return true;

  return false;

and then in your HTML :

<th ng-hide="shouldHideColumn(value)" ng-repeat="(key, value) in localNew[0]">