AngularJS网格没有数据消息

时间:2015-04-27 19:36:35

标签: angularjs

我只是想知道这是否是一种显示方式"没有可用数据"如果控制器返回的json是空的,而不是网格?在下面的代码中,gridData存储控制器返回的json

<div class="row">

    <table class="table table-striped table-hover ">
        <thead>
            <tr>
                <td><b>Format</b></td>
                <td><b>Day of Month</b></td>
                <td><b>Day of Week</b></td>
                <td></td>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="i in gridData">
                <td>{{i.Id}}</td>
                <td>{{i.DayofMonth}}</td>
                <td>{{i.DayofWeek}}</td>
                <td><button class="btn btn-danger" ng-click="delete('{{i.Id}}')">Delete</button></td>
            </tr>
        </tbody>
    </table>
</div>

2 个答案:

答案 0 :(得分:2)

您可以使用ng-switch

<div class="row">
  <div ng-switch="gridData">
    <div ng-switch-when="gridDataIsEmpty()">No data available</div>
    <div ng-switch-when="!gridDataisEmpty()"> <!-- Normal table Code --> </div>
  </div>
</div>

答案 1 :(得分:1)

试试这个:

<div class="row">

        <table class="table table-striped table-hover " ng-if="gridData.length > 0">
            <thead>
                <tr>
                    <td><b>Format</b></td>
                    <td><b>Day of Month</b></td>
                    <td><b>Day of Week</b></td>
                    <td></td>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="i in gridData">
                    <td>{{i.Id}}</td>
                    <td>{{i.DayofMonth}}</td>
                    <td>{{i.DayofWeek}}</td>
                    <td><button class="btn btn-danger" ng-click="delete('{{i.Id}}')">Delete</button></td>
                </tr>
            </tbody>
        </table>

    <div ng-if="gridData.length === 0">No data available</div>
    </div>