How to get selected value from ng-repeat

后端 未结 2 1227
有刺的猬
有刺的猬 2021-01-07 13:10

This is my code.

I m getting data through ng-repeat and showing it as shown in below code.

What I want is if I click on either of the name then it should ale

相关标签:
2条回答
  • 2021-01-07 13:23

    You need to modify html and add selectInfo function in controller file.

    html

    <table>
          <tr ng-repeat="x in record">
                        <th>{{x.id}}</th>
                        <th ng-click="selectInfo(x.firstname)">    {{x.firstname}}</th>
                        <th ng-click="selectInfo(x.middlename)">{{x.middlename}}</th>
                        <th ng-click="selectInfo(x.lastname)">{{x.lastname}}</th>
                      </tr>
        </table>
    

    code

    $scope.selectInfo=function(name){
    alert(name);
    }
    
    0 讨论(0)
  • 2021-01-07 13:32

    You are going good so far. You added the ng-click event. But aal you need to do to get the name in controller is, you need to paas the current item as arguement See Here <th ng-click="selectInfo(x)">{{x.firstname}}</th>

    and in the controller make a function

    $scope.selectInfo = function (item) {
       alert(item.firstname);
       // Or use this to do whatever you want
    }
    
    0 讨论(0)
提交回复
热议问题