我正在编写一个将呈现表格的指令。它的主要“参数”是表头和数据,我将其作为控制器的属性传递。问题是我的一些数据不会传递给我的指令,即使我使用2路数据绑定。这是代码:
ze指令:
Application.directive('ngDataTable', function () {
return {
restrict : 'E',
replace : true,
templateUrl : '/templates/directives/datatable.html',
scope : {
headers : '=',
dataMatrix : '='
},
link: function (scope, elem, attrs) {
}
}
});
ze指令模板(datatable.html):
<div class="table-wrapper">
<table class="default hover sticky">
<thead>
<tr>
<th ng-repeat="header in headers"> <% header %> </th>
</tr>
</thead>
<tbody>
<% dataMatrix %>
</tbody>
</table>
</div>
ze控制器:
Application.controller('CycleCountingLogsController', ['$http', '$scope', 'initData', function( $http, $scope, initData){
.... some code
logs.tableHeaders = [
'Name', 'Product Id', 'Building Quantity', 'Post Quantity', 'Picked Quantity', 'Qty. on Orders', 'Quantity Change', 'Ov. Found', 'Ov. Included', 'Ch. Found', 'Ch. Included', 'Created At'
];
logs.dataMatrix = initData.data.logs; // initData is a service that fetches data by AJAX for each view that needs initial data, and logs is a matrix (table rows, cell values)
....
和指令的ze html声明:
<ng-data-table headers="logs.tableHeaders" data-matrix="logs.dataMatrix"></ng-data-table>
标题显示,但矩阵数据不显示。为什么呢?