我有下一个指令
angular
.module('01')
.directive('tableSortable', tableSortable);
/** @ngInject */
function tableSortable() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'app/components/tabla/tableSortable.html',
scope: {
columns: '=',
data: '=',
sort: '=',
onclickRow: '='
}
我有下一个显示表格的HTML
<tbody>
<tr ng-click="click(object)" ng-repeat="object in data | orderBy:sort.column:sort.descending | orderBy:sort.column:sort.descending | startFrom:currentPage*pageSize | limitTo:pageSize">
<td
ng-repeat="key in object"
ng-if="key != '$$hashKey'" >
{{object[columns[$index].variable] | customFilter : getFilterOfColumn(columns[$index].variable)}}
</td>
</tr>
</tbody>
我有另外的html,我称之为指令
<table-sortable onclick-row="main.onclickRow(msg)"
columns="main.columnsBusquedas" data="main.rowsBusquedas" sort="main.sortBusquedas">
</table-sortable>
此控制器带有onclickRow(msg)功能,我想取用户点击的行
function onclickRow(msg){
$log.debug(msg);
}
这段代码不起作用......你能帮帮我吗?
感谢。
答案 0 :(得分:1)
更改绑定函数的指令部分,应使用&
而不是=
function tableSortable() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'app/components/tabla/tableSortable.html',
scope: {
columns: '=',
data: '=',
sort: '=',
click: '&onclickRow' // this how we call function from directive...
}
在HTML中更改您的ng-click
,如下所示..
<tbody>
<tr ng-click="click({'msg':object})" ng-repeat="object in data | orderBy:sort.column:sort.descending | orderBy:sort.column:sort.descending | startFrom:currentPage*pageSize | limitTo:pageSize">
<td
ng-repeat="key in object"
ng-if="key != '$$hashKey'" >
{{object[columns[$index].variable] | customFilter : getFilterOfColumn(columns[$index].variable)}}
</td>
</tr>
</tbody>