这是HTML,其中有用于获取列表的ng-repeat,以及最初已经冻结的ng-readonly,以及在JS上发布的点击函数
<tr ng-repeat= "employeeDetail in employeeDetails">
<div ng-readonly="isReadonly">
<td><a><span>{{employeeDetail.empName}}</a></td>
<td>
<div ng-if="employeeDetail.departmentName">
{{employeeDetail.departmentName}}
</div>
<div ng-if="!employeeDetail.departmentName">
Not Specified
</div>
</td>
<td>
{{employeeDetail.empEmail}}
</td>
<td>{{employeeDetail.empContact}}</td>
<td>
<i class="fa fa-edit" ng-click="updateEmp()">
</td>
</div>
</tr>
这是附加到它的JS文件,我想要的是在点击时使所有字段都可编辑,
$scope.isReadonly = false;
$scope.addEmployeeType = function(){
var employeeDetail = new employeeDetailApi();
$scope.employeeDetails = employeeDetail.list;
}
$scope.updateEmp = function (){
$scope.isReadonly = true;
console.log("update Employee");
}
答案 0 :(得分:1)
只需将您的HTML更新为
即可<div ng-readonly="isReadonly" ng-click="!isReadonly">
就是这样!
答案 1 :(得分:1)
尝试一下......
<tr ng-repeat= "employeeDetail in employeeDetails">
<div ng-click="isReadonly==true">
<td><input type="text" ng-value="employeeDetail.empName" ng-readonly="isReadonly"></td>
<td><input type="text" ng-value="employeeDetail.departmentName" ng-readonly="isReadonly"></td>
<td><input type="text" ng-value="employeeDetail.empEmail" ng-readonly="isReadonly"></td>
<td><input type="text" ng-value="employeeDetail.empContact" ng-readonly="isReadonly"></td>
<td>
<i class="fa fa-edit" ng-click="updateEmp()">
</td>
</div>
</tr>