1

I have an input text with a table in which I filter some values from a JSON with an ng-repeat in meanwhile I'm typing.

<input type="text" placeholder="Choose" ng-model="item.sTxt"/>
   <table>
      <thead>
         <tr>
            <th>First Value</th>
            <th>Second Value</th>
         </tr>
      </thead>
      <tbody>
         <tr
             data-ng-repeat="item in numberList.getList | filter:searchText" 
             ng-click="setSelected(item.last)">
             <td>{{item.first}}</td>
             <td>{{item.last}}</td>
         </tr>
      </tbody>
  </table>

I can show an alert when I click a row in the table in this way:

$scope.idSelectedVote = null;
    $scope.setSelected = function (idSelectedVote) {
        $scope.idSelectedVote = idSelectedVote;
        alert(idSelectedVote);
    }; 

but i would take that value and pass it in my input text. How could i do it in angularjs?

1 Answer 1

4

you can use ng-model to create a model on text input, then just pass the value of clicked table row to that model, like this

<input ng-model='input' type="text" placeholder="Choose"/>



$scope.setSelected = function (idSelectedVote) {
        $scope.idSelectedVote = idSelectedVote;
        $scope.input=idSelectedVote;
        //alert(idSelectedVote);
    };


Also if you want to filter out the repeated list, you can use the same model, in the filter.

you can see this Fiddle, it does both filter on input and place text in input on click of tr

Sign up to request clarification or add additional context in comments.

16 Comments

doesn't work :( consider that i have alread an ng-model in my input (sorry i have forgotten to write it)
@endgame can you create a fiddle of your problem.. the one I created works fine if ng-model used.. try the way i have done
this is so strange...same case tried in fiddle and no problems.. In mine i can view the clicked item on the console but i can't pass it into the input!!
Ok, now this one jsfiddle.net/8y48q/11 is very similiar at my case.. and doesn't work
@End.Game.. That question has a different context.. you can post a different question.. also notify me if you do..
|

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.