无法注册Angular控制器

时间:2018-08-01 08:37:59

标签: angularjs json

我知道有很多相同的主题,但是我找不到答案。

我创建了一个简单的表,并用JSON中的数据填充了该表,但该表未加载,并且出现此错误:

  

名称为“ TableDataController”的控制器未注册。

<div class = "customtable" style="overflow:auto;" ng-style="{height:position.height+'px', width:position.width+'px'}">
<div ng-app="TableFill" ng-controller="TableDataController">
    <table style="table-layout: fixed;">
        <thead class="customtable-title">
            <tr>
                <th class="customtable-title-cell">Время погрузки</th>
                <th class="customtable-title-cell">Назначение</th>
                <th class="customtable-title-cell">Расчётное качество</th>
                <th class="customtable-title-cell">Качество по ЯФО</th>
                <th class="customtable-title-cell">Отклонение от планового</th>
            </tr>
        </thead>
        <tbody>
            <tr class="customtable-grid-row" ng-repeat="load in loadingTimes">
                <td>{{load.loadingTime}}</td>
                <td>{{load.target}}</td>
                <td>{{load.quality}}</td>
                <td>{{load.yafo}}</td>
                <td>{{load.deviation}}</td>
            </tr>
        </tbody>
    </table>
</div>
<script>
var app = angular.module("TableFill", []);
app.controller('TableDataController', function ($scope) {
    $scope.loadingTimes = [                
        { 'loadingTime': '001', 'target': 'Alpha', 'quality': 37, 'yafo': 37, 'deviation': 37 },
        { 'loadingTime': '002', 'target': 'Bravo', 'quality': 27, 'yafo': 37, 'deviation': 37 },
        { 'loadingTime': '003', 'target': 'Charlie', 'quality': 29, 'yafo': 37, 'deviation': 37 },
        { 'loadingTime': '004', 'target': 'Delta', 'quality': 19, 'yafo': 37, 'deviation': 37 },
        { 'loadingTime': '005', 'target': 'Echo', 'quality': 32, 'yafo': 37, 'deviation': 37 }];           
} );
</script>
</div>

1 个答案:

答案 0 :(得分:0)

您应该修复脚本代码  来自

app.controller('TableDataController', function ($scope){ ... code ...} );

app.controller('TableDataController',['$scope', function ($scope) {...code..}]);