2016-11-11 75 views
0

這裏我的問題: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

回答

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

0

試試這個:

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

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