ng表中的数据没有显示

问题描述:

这里我的问题:ng表中的数据没有显示

我想建立一个指令在角度,这将使用ng表内。我正在使用模拟数据。问题是我无法在表格中呈现数据。这里是我的指令:

;(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

更改您的指令'ngTable',不'ngTables' – raven

+0

这不是因为指令名的,问题是,数据是空的 – fishera

+0

从那里你得到'$ data'的名字? – Sravan

更换

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.tableParams = new NgTableParams({},{ scope.data:dataset })'不起作用 – fishera

试试这个:

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

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