Get the <td> onclick value for another <td> of the same row with Angular

I would like to get the value of a data cell <td>if I click on another of <td>the same row.

 <tr ng-repeat="x in names">
   <td>{{ x.Name }}</td>
   <td>{{ x.Country | uppercase }}</td>
 </tr>

One way to solve it is for example http://jsfiddle.net/L60L3gv9/

$scope.getValueOfTD = function(x){
    alert(x.Name);    
}

But in my case there is no connection between my data cells. Is there a way to get this value with a standard function, for example?

$scope.getValueOfTD = function(){

}

Any decisions are ok

+4
source share
1 answer

You can use ng-clickon tr:

Jsfiddle

HTML:

<table>
  <th>Column1</th>
  <th>Column2</th>
  <tr ng-repeat="x in names" ng-click="getValueOfTD(x)">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country | uppercase }}</td>
  </tr>
</table>

JS:

$scope.getValueOfTD = function (user) {
    console.log(user.Name);
}
+3
source

Source: https://habr.com/ru/post/1619810/


All Articles