Angular заполняет данные, но не показывает данных - PullRequest
0 голосов
/ 03 мая 2018

Я новичок в angularjs и пытаюсь заполнить данные на веб-странице с помощью ng-repeat

<tr ng-repeat="d in dataList">
   <td> {{d.name}} </td>
   <td> {{d.email}} </td>
   <td> {{d.address}} </td>
   <td> {{d.phone}} </td>
</tr>

и подержанные jquery

angular.element(document).ready(function() {  
   dTable = $('#table')  
   dTable.DataTable();
});

Данные заполняются просто отлично, а также таблицы преобразуются в таблицы данных. но то, что я получаю, это то, что строки не встроены в таблицы данных.

печатает данные, но также показывает отсутствие доступных данных и показывает 0 записей

Посмотрите на скриншот здесь

любая помощь будет признательна.

index.html

<!DOCTYPE html>
<html lang="en" ng-app="app" class="no-js">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="/css/app.css">
<link rel="stylesheet" href="/css/utopiapk.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.angularjs.org/1.6.9/angular.js"></script>
<script src="https://code.angularjs.org/1.6.9/angular-resource.js"></script>
<script src="https://code.angularjs.org/1.6.9/angular-route.js"></script>
<script src="/js/app.js"></script>
<script src="/js/controller.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" ></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" ></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js" ></script>
<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js" ></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.0.0/ui-bootstrap-tpls.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-utils/0.1.1/angular-ui-utils.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.0.0/ui-bootstrap-tpls.min.js" ></script>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css">

<script src="/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="/css/datatables.bootstrap.css"> 


</head>

<body>

<div ng-view style="padding:2%">
 <table id="vendors" class="table table-striped table-bordered dtable" style="width:100%" > 
            <thead>
                <tr>
                    <th>Vendor Code</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Address</th>
                    <th>Phone</th>
                    <th></th>

                </tr>
            <thead>
            <tbody>
                <tr ng-show="vendors.length" ng-repeat="v in vendors"  >
                    <td>{{v.vendorCode}} </td>
                    <td>{{v.name}} </td>
                    <td>{{v.email}} </td>
                    <td>{{v.address}} </td>
                    <td>{{v.phone}} </td>
                    <td><i class="fas fa-edit"></i> </td>
                </tr>
            </tbody>
        </table>

</div>

<script type="text/javascript">
$(document).ready(function() {
    $('#vendors').DataTable();
 } );
</script>

</body>
</html>

А вот и мой controller.js

app.controller('productsController', function($scope, $http) {
    $http({
        method : 'GET',
        url : 'getAll'
    })
    .then(function(response, status, headers, config) {
        $scope.vendors= response.data;
        $scope.headingTitle= "Vendor";
    })
    .catch(function(data, status) {
        console.error('Repos error', status, data);
    })
});

1 Ответ

0 голосов
/ 04 мая 2018

используйте ng-show="dataList.length" для таблицы списка данных и

используйте ng-show="!dataList.length" для сообщения div.

например.

<tr ng-show="dataList.length" ng-repeat="d in dataList">
   <td> {{d.name}} </td>
   <td> {{d.email}} </td>
   <td> {{d.address}} </td>
   <td> {{d.phone}} </td>
</tr>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...