是否可以将ng-repeat值分配给文本框

时间:2017-12-31 14:36:20

标签: javascript html angularjs

<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>

我正在尝试将user.AdmissionID指定为文本框中的值。有可能吗?

1 个答案:

答案 0 :(得分:2)

是使用 ng-model ,它会将您的值绑定到文本框

<强>样本

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>