我在一个项目中使用angular-datatables。我是这样使用它的:
<table datatable="ng" class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>First</th>
<th>Last</th>
<th>Occupation</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in people">
<td>{{person.Id}}</td>
<td>{{person.FirstName}}</td>
<td>{{person.LastName}}</td>
<td>{{person.Job}}</td>
</tr>
</tbody>
</table>
奇怪的是,该表呈现。但是,它的行为与数据表不同。未加载排序。有没有办法让我检查一下datatables
是否已经加载?在我的页面中,我有以下内容:
<link href="/libs/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="/libs/angular-datatables/dist/datatables.bootstrap.min.css" rel="stylesheet"/>
<script src="/libs/jquery/dist/jquery.min.js"></script>
<script src="/libs/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="/libs/angular/angular.min.js"></script>
<script src="/libs/angular-datatables/dist/angular-datatables.min.js"></script>
<script src="/js/app.js"></script>
angular.bootstrap($('#myApp'), ['myApp']);
MyApp是手动引导的,因为页面上有多个应用程序。app.js
具有以下特性:
'use strict';
var myApp = angular.module('myApp', ['ngAnimate', 'ui.bootstrap', 'datatables', 'app.components']);
myApp.controller('MyController', ['$scope',
function ($scope, DTOptionsBuilder, DTColumnDefBuilder) {
console.log(DTOptionsBuilder);
}])
;
console.log语句打印undefined
。这对我来说意味着datatables
没有被加载。然而,我不确定如何确认这一点。我在控制台窗口中看不到任何404。所以,我假设我至少下载了必要的库。感觉好像我没有正确地注入datatables
。然而,在我看来,它是正确的。然而,排序不起作用,DTOptionsBuilder
打印未定义。
我做错了什么?
发布于 2015-01-01 11:25:43
没有正确地提供Inline Array Annotation
,正确的方法是:
myApp.controller('MyController', ['$scope', 'DTOptionsBuilder', 'DTColumnDefBuilder',
function ($scope, DTOptionsBuilder, DTColumnDefBuilder) {
console.log(DTOptionsBuilder);
}])
;
https://stackoverflow.com/questions/26742826
复制