我正在使用开源Angular JS theme SB Admin我完成了很多工作。但是我想添加Angular JS ng-table它会让我跟随错误:
TypeError: a.reload is not a function
at Object.fn (ng-table.min.js:3)
at h.$digest (angular.min.js:106)
at h.$apply (angular.min.js:109)
at f (angular.min.js:71)
at F (angular.min.js:75)
at XMLHttpRequest.x.onreadystatechange (angular.min.js:76)
编辑:: 由于主题代码很大,我创建了一个只有必需的东西的小小提琴脚本,我得到了上述内容,“newParams.reload不是一个函数,10美元消化()迭代到达。中止!“错误。
请检查Fiddle。表似乎对我的项目很重要,任何建议都有帮助。
答案 0 :(得分:4)
由于我在很多论坛中搜索了2天以找到这个问题的解决方案,我无法找到并感谢很少有人来帮助解决这个问题。
无论如何,我发现实际问题很简单,“当你使用NgTableParams时,请不要使用'NgTableParams'变量作为范围变量,总是尝试将它用作类变量”。
我不知道原因,为什么我们要使用类变量。但是从我的角度来看(我的结论是基于错误),因为Angular JS中的范围变量会暴露给观察者并进入摘要周期,所以它会给出这个问题。
以下示例很棒:
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="./dist/bootstrap.min.css">
<link rel="stylesheet" href="./dist/bootstrap-theme.min.css">
<!--[if lt IE 9]>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<![endif]-->
<script src="./dist/angular.js"></script>
<script src="./dist/ng-table.js"></script>
<link rel="stylesheet" href="./dist/ng-table.css">
<body ng-app="main">
<div ng-controller="DemoCtrl as demo">
<table ng-table="demo.tableParams" class="table" export-csv="csv" ng-table-columns-binding="demo.columns">
<tr ng-repeat="user in $data">
<td data-title="'Name'" ng-if="true">
{{user.name}}
</td>
<td data-title="'Age'" ng-if="true" filter="{ age: 'text'}">
{{user.age}}
</td>
</tr>
</table>
<!-- <table ng-table="demo.tableParams" class="table" show-filter="true">
<tr ng-repeat="user in $data">
<td title="'Name'" filter="{ name: 'text'}" sortable="'name'">
{{user.name}}</td>
<td title="'Age'" filter="{ age: 'number'}" sortable="'age'">
{{user.age}}</td>
</tr>
</table>
--></div>
<script>
var app = angular.module('main', ['ngTable']).
controller('DemoCtrl', function($scope, NgTableParams ) {
var self = this;
$scope.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}];
self.tableParams = new NgTableParams({
}, {
dataset: $scope.data
});
});
</script>
</body>
</html>
答案 1 :(得分:0)
通过初始化$scope.tableParams = new NgTableParams({}, { dataset:[] })
为我工作
谢谢