John Smith John Smith - 2 years ago 77
AngularJS Question

How to use track the user selection and present in display Angular JS?

I want to track whatever the user selects in the table and present in another form using Angular JS. I am quite stuck on how to perform this activity. My first attempt is to use track by but it does not get called.

user.html

<div>
<tr ng-repeat="usrInput in usrInputs | filter:searchData track by $index" ng-click="clickValidValues()">
<td>{{usrInput.name}}</td>
<td><button ng-click="clickValidValues()"> Update </button></td>
</tr>
</div>


Now, Whatever the user selects, I want that data to be presented in the form below.

<div>
<form>
<input class="form-control" ng-repeat="usrInput in usrInputs" type="text" disabled>
{{usrInput.name}}
</input>
</form>
</div>


user.js

$scope.usrInput = [
{name: "Mike"},
{name: "Bir"},
];

Answer Source

So for that you can do is -

user.html -

<div>
<tr ng-repeat="usrInput in usrInputs |   filter:searchData track by $index" 
 ng-click="clickValidValues()">
<td>{{usrInput.name}}</td>
<td><button ng-click="clickValidValues(usrInput.name})"> Update </button>
</td>
</tr>
</div>

<div>
<form>
  <input class="form-control" ng-repeat="usr in newInputs" 
  ng-model="usr" type="text"disabled>

</input>
</form>
</div>

user.js-

$scope.newInputs=[];
$scope.usrInput = [
    {name: "Mike"},
    {name: "Bir"},
];

$scope.clickValidValues = function(name){
   $scope.newInputs.push(name);

 }

Hope this is what you need add the user names in a new array and repeat that new array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download