这里是我的问题:
我正在尝试在angular中构建一个指令,它将在内部使用ng-table。我正在使用模拟数据。问题是我无法在表格中呈现数据。这是我的指示:
;(function(app) {
app.directive('customTables', [
'NgTableParams',
function(NgTableParams) {
return {
restrict: 'E',
templateUrl: 'templates/directives/table_directive.html',
scope: {
},
link: function(scope) {
var dataset = [{
name: "Moroni50",
age: "50"
}, {
name: "Moroni49",
age: "49"
}];
scope.tableParams = new NgTableParams({}, {
data: dataset
});
}
};
}]);
})(app);
这是html:
<table ng-table="tableParams" class="table table-bordered table-striped table-condensed">
<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>
这就是我如何称呼它:
<custom-table></custom-table>
有什么建议吗?
答案 0 :(得分:0)
替换
:
与
scope.tableParams = new NgTableParams({}, {
data: dataset
});
并在html中:
scope.tableParams = new NgTableParams({}, {
scope.data: dataset
});
带
<tr ng-repeat="user in $data">
答案 1 :(得分:0)
试试这个:
scope.data = [{
name: "Moroni50",
age: "50"
}, {
name: "Moroni49",
age: "49"
}];
scope.tableParams = new NgTableParams({}, {
data: scope.data
});
答案 2 :(得分:0)
试试看
scope.tableParams =新的NgTableParams({},{ 数据集:数据集 });