Jed Matthew Lina
Jed Matthew Lina

Reputation: 29

Is it possible to assign ng-repeat value to a textbox

<tr ng-repeat="user in users" ng-class="{'selected': user.AdmissionID == selectedRow}" ng-click="setClickedRow(user.AdmissionID)">
    <td>{{user.AdmissionID}}</td>
    <td>{{user.AdmissionNo}}</td>
    <td>{{user.AdmissionDateTime}}</td>
    <td>{{user.Lname}}, {{user.Fname}} {{user.Mname}} </td>
    <td>{{user.Admission}}</td>
    <td>{{user.AdmissionType}}</td>
    <td>{{user.Gender}}</td>
    <td>{{user.Address}}</td>          
</tr>

I'm trying to assign user.AdmissionID as a value in a text box. Is it possible?

Upvotes: 1

Views: 47

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222572

Yes use ng-model which will bind your value to text box

DEMO

var app =angular.module('testApp',[]);
app.controller('testCtrl',function($scope){

$scope.users = [{
  "AdmissionID": "Klimovsk",
  "AdmissionNo": 23   
}, {
  "AdmissionID": "Shalakusha",
   "AdmissionNo": 23 
}];

$scope.setClickedRow =function(user){
  $scope.selectedAdmissionID = user.AdmissionID;
}

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
 <table>
 <tr ng-repeat="user in users"  ng-click="setClickedRow(user)">
    <td>{{user.AdmissionID}}</td>
    <td>{{user.AdmissionNo}}</td>      
</tr>
 <table>
   <input type="text" ng-model="selectedAdmissionID">
 </body>

Upvotes: 2

Related Questions