我是带有datatable的angular js的新手,并且在页面加载时遇到问题,我正在尝试使用angular js添加加载datatable。
错误:
angular.js:138 Uncaught Error: [$injector:modulerr] Failed to instantiate module PMS due to:
Error: [$injector:modulerr] Failed to instantiate module angularMoment due to:
Error: [$injector:nomod] Module 'angularMoment' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
详细信息错误 Error link
我的控制器
var app = angular.module('PMS', ['angularMoment', 'ui.router', 'datatables'])
.filter('jsonDate', ['$filter', function($filter) {
return function(input, format) {
return (input) ? $filter('date')(parseInt(input.substr(6)), format) : '';
};
}]);
app.controller('SpaceController', function($scope, SpaceService) {
$scope.getAll = function() {
loader(true);
var getData = SpaceService.getAllData();
getData.then(function(response) {
if (response.data.success) {
$scope.listdt = response.data.data;
$scope.populateStatus();
loader(false);
} else {
errorAlert("Oops", response.data.message);
loader(false);
}
});
}
});
我的模板
@ {
Layout = null;
} <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link href="~/Scripts/PMS_theme_js/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="~/Content/PMS_theme_css/css/style.css" rel="stylesheet">
</head>
<body ng-app="PMS" ng-controller="SpaceController">
<table datatable="ng" class="table display" id="TblID">
<thead>
<tr>
<th>ID</th>
<th>Key</th>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="d in listdt">
<td>{{d.SpaceID}}</td>
<td>{{d.SpaceKey}}</td>
<td>{{d.SpaceName}}</td>
<td>{{d.SpaceDesc}}</td>
<td> <span class="label label-table {{d.StatusKey == 'A' ? 'label-success' : 'label-red'}}">{{d.StatusName}}</span></td>
<td>
<a class="btn btn-primary btn-sm" ng-click="edit(d)"><i class="fa fa-pencil fa-lg"></i></a>
<a class="btn btn-danger btn-sm" ng-click="delete(d)"><i class="fa fa-trash fa-lg"></i></a>
</td>
</tr>
</tbody>
</table>
<script src="~/Scripts/PMS_theme_js/plugins/bower_components/jquery/dist/jquery.min.js"></script>
<script src="~/Scripts/PMS_theme_js/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="~/Scripts/datatables/media/js/jquery.dataTables.js"></script>
<script src="~/Scripts/angular-datatables/dist/angular-datatables.js"></script>
<script src="~/Scripts/Angular/Module.js"></script>
</body>
</html>
它与Datatable可以正常工作,但是当添加 datatable 模块时,它开始出现错误。任何原因以及我在Angular js数据表中做错了什么。
答案 0 :(得分:1)
您提到的错误表明您没有正确注入
angularMoment
,请参考 documentation 。
确保在您的应用程序中同时包含了 moment.js 和 angular-moment.js ,在您的情况下,看起来像是-
<script src="~/Scripts/moment/moment.js"></script>
<script src="~/Scripts/angular-moment/angular-moment.js"></script>