表格数据未显示

问题描述 投票:0回答:3

在这里我的问题:

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

有什么建议?

angularjs angular-directive ngtable
3个回答
0
投票

更换

scope.tableParams = new NgTableParams({}, {
                        data: dataset
                    });

scope.tableParams = new NgTableParams({}, {
                        scope.data: dataset
                    });

并在HTML中:

<tr ng-repeat="user in $data">

<tr ng-repeat="user in data">

0
投票

试试这个:

scope.data = [{
                    name: "Moroni50",
                    age: "50"
                }, {
                    name: "Moroni49",
                    age: "49"
                }];

                scope.tableParams = new NgTableParams({}, {
                    data: scope.data
                });

0
投票

试试这个

scope.tableParams = new NgTableParams({},{dataset:dataset});

© www.soinside.com 2019 - 2024. All rights reserved.