gpt4 book ai didi

angularjs-routing - ngTable with angular-routing = undefined 不是函数

转载 作者:行者123 更新时间:2023-12-01 05:15:00 24 4
gpt4 key购买 nike

请帮忙。我被困在这一点上超过 14 小时,我找不到解释或例子。

这就是我现在所拥有的:
http://plnkr.co/edit/PaYR7c0QXSKxl1jcmRBQ

如果我不使用角度路由,ngTable 可以正常工作。一旦我添加路由,它就会出现这个错误。
当我评论 $scope.tableParams = new ngTableParams({
...但是数据没有显示。

不起作用的代码:

    var app = angular.module('main', [
'ngRoute',
'ngTable'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {templateUrl: 'partial1.html', controller: 'MyCtrl1'});
$routeProvider.otherwise({redirectTo: '/'});
}]);

app.controller('MyCtrl1', [function($scope,ngTableParams) {
var data = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];

$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}]);
</script>
</head>

<body ng-app="main">
<div ng-view=""></div>
</body>

最佳答案

应该更正 HTML 标题:(您在 angular 之前加载了 ngTable)

<script>document.write('<base href="' + document.location + '" />');</script>
<script data-require="angular.js@*" data-semver="1.2.10" src="http://code.angularjs.org/1.2.10/angular.js"></script>
<script data-require="angular-route@*" data-semver="1.2.10" src="http://code.angularjs.org/1.2.10/angular-route.js"></script>
<script data-require="ng-table@*" data-semver="0.3.0" src="http://bazalt-cms.com/assets/ng-table/0.3.0/ng-table.js"></script>

Controller 声明有点不对。
app.controller('MyCtrl1', ['$scope', 'ngTableParams', function MyCtrl1($scope, ngTableParams) {

关于angularjs-routing - ngTable with angular-routing = undefined 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21412979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com