ng-table数据未显示

时间:2016-11-11 13:06:16

标签: angularjs angular-directive ngtable

这里是我的问题:

我正在尝试在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>

有什么建议吗?

3 个答案:

答案 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({},{                         数据集:数据集                     });