HangulSR
HangulSR

Reputation: 259

Angularjs ng-show for table

I am trying to make a button to show up only when there's a table in ng-view. How do i code it to do that? How should the condition be written to achieve that? Thanks for the help in advance!

HTML:

<main ng-view>
</main>
<button onclick="exportTableToExcel('tableToCsv')" type="button contact- 
button" class="btnDL" ng-show="toDLTable()">XLSX Download</button>

Upvotes: 0

Views: 70

Answers (2)

Gaurav Singh
Gaurav Singh

Reputation: 369

Try this

ControllerCode

$scope.x = document.getElementsByTagName("table");

In HTML

<button onclick="exportTableToExcel('tableToCsv')" type="button contact- 
button" class="btnDL" ng-if="x.length>0" ng-show="toDLTable()">XLSX Download</button>

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222522

Probably you need to have a div to identify,

<div class="view-container">
    <main  ng-view>
    </main>
</div>

Now inside your controller,

$scope.CheckContent = function(){
   var theView = document.getElementsByClassName("view-container")[0].getElementById("myView").getElementsByClassName("container")[0];
   if(theView != null && theView == ''){
      $scope.showTab = true;
   }
  }
}

and bind it in HTML

<button onclick="exportTableToExcel('tableToCsv')" type="button contact- 
button" class="btnDL" ng-show="showTab">XLSX Download</button>

Upvotes: 0

Related Questions