我尝试创建将简化 HTML 的指令。现在 html 看起来像:
<tr>
<th class="span3" ng-click="setSorting('status')" ng-class="columnClass('status')">
title1
<div class="sorted-image">
<i ng-class="iconClass('status')"></i>
</div>
</th>
<th class="span4" ng-click="setSorting('sensorIdOrder')" ng-class="columnClass('sensorIdOrder')">
title2
<div class="sorted-image">
<i ng-class="iconClass('sensorIdOrder')"></i>
</div>
</th>
<th class="span3">
title3
</th>
</tr>
其中 setSorting 是用于排序和设置值的函数,用于 ng-repeat:
<tr ng-repeat="s in getData()| orderBy : sorting.field : !sorting.asc">
我想创建 thsort 指令,它包含所有函数(setSorting、columnClass、iconClass)并且只使用一个参数参数
<tr>
<thsort class="span3" sort-field = "status")">
title1
</thsort>
<thsort class="span4" sort-field = "sensorIdOrder">
title2
</thsort>
<th class="span3">
title3
</th>
</tr>
编译后的所有参数(Like argument)也适用于