这是 plnkr:http ://plnkr.co/HVnZWK5dNuvu180HCT6o
我以为我写了一个简单的指令,只是table
稍微重写了一些元素。目的是让嵌入的主体针对父范围做自己的事情。这是一个玩具,我知道,但我正在尝试推出一个“更智能”的桌子,但我无法超越基础知识。
数据表.js:
angular.module('daTable', [])
.directive('daTable', function() {
return {
restrict: 'E',
replace: true,
templateUrl: 'templates/da-table.html',
transclude: true,
scope: {}
}
});
da-table.html:
<table class="table table-bordered table-striped table-hover table-condensed" border="1">
<caption>Table</caption>
<thead><tr><th>column 1</th></tr></thead>
<tbody ng-transclude></tbody>
</table>
main.html(通过 $routeProvider 的路由视图)
...
<da-table>
<tr ng-repeat="r in rows">
<td>{{r.col1}}</td>
<td>{{r.col2}}</td>
<td>{{r.col3}}</td>
</tr>
</da-table>
...
主.js:
dataTableApp.controller('MainCtrl', function($scope) {
$scope.rows = [
{col1: "data 1,1", col2: "data 1,2", col3: "data 1,3"},
{col1: "data 2,1", col2: "data 2,2", col3: "data 2,3"},
{col1: "data 3,1", col2: "data 3,2", col3: "data 3,3"}
]
});