简体   繁体   中英

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>

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM