0

I have the next directive

  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: '='
  }

and I have the next html that shows a table

<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>

I have this other html where I call the directive

  <table-sortable onclick-row="main.onclickRow(msg)"
    columns="main.columnsBusquedas" data="main.rowsBusquedas" sort="main.sortBusquedas">
    </table-sortable>

And this controller with a function onclickRow(msg) where I want to take the row that the users click on

function onclickRow(msg){
  $log.debug(msg);
}

This code didn't work... Could you help me please?

Thanks.

2
  • 1
    Shouldn't the ng-click in the template be calling onclickRow(...) rather than click(...)? And also I think you need to pass the object parameter via an object {msg: object} Commented Oct 27, 2016 at 15:19
  • @jose did it work for you ? Commented Oct 28, 2016 at 9:58

1 Answer 1

1

Change your directive part where you bind function, you should use & instead of =

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...
  }

In HTML change your ng-click like below..

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.