https://plnkr.co/edit/z7I2zewXwvovZ8023rHm?p=preview
请帮助我在上面的plnkr中使用这个ngTable示例。我无法显示表格,当我看到控制台日志时,模板有单个元素的错误。
代码: 的script.js
angular.module("myApp", ["ngTable"]);
angular.module('myApp')
.controller('myCtrl',function($scope,NgTableParams){
var self = this;
var data = [{name: "Moroni", age: 50},{name: "Moroni", age: 50},{name:"Moroni", age: 50}];
self.tableParams = new NgTableParams({}, { data: data});
});
的index.html
<body ng-app="myApp" controller="myCtrl as vm">
{{8+7}}
<table ng-table="tableParams" class="table" show-filter="true">
<tbody>
<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>
</tbody>
</table>
答案 0 :(得分:0)
您引用脚本的顺序是错误的,script.js应该在加载ng-table
后加载
<div class="container">
<table ng-table="vm.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>
答案 1 :(得分:-1)
尝试这个
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.2.0" data-semver="1.2.0" src="https://code.angularjs.org/1.2.0/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/esvit/ng-table/1.0.0/dist/ng-table.min.css">
<script src="https://cdn.rawgit.com/esvit/ng-table/1.0.0/dist/ng-table.js"></script>
<script>
// Code goes here
angular.module("myApp", ["ngTable"])
.controller('myCtrl',function($scope,NgTableParams){
var self = this;
var data = [{name: "Moroni", age: 50},{name: "Moroni", age: 50},{name: "Moroni", age: 50}];
self.tableParams = new NgTableParams({}, { dataset: data});
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl as vm">
{{8+7}}
<table ng-table="vm.tableParams" class="table" show-filter="true">
<tbody>
<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>
</tbody>
</table>
</body>
</html>