我有一个带有两个输入框的表,使用ng-repeat我遍历了这些值,

<tr ng-repeat = "row in allRows" >
<td>

<input type="text" ng-model="row.name" ng-readonly="toogleRN && $first"/>
</td>
<td>
<input type="number" ng-model="row.age" ng-readonly="toogleRN && $first"/>
 </td>
 <td>
  <a role="button" class="btn btn-sm btn-default "
                         data-ng-click="toogleIt()" data-ng-show="$first"><span class="glyphicon glyphicon-search"> Edit</span>
                      </a>
 </td>
 </tr>
 </table>


我的控制者是我的控制者

var app =  angular.module("TableDemo",[]);
app.controller('TableController',['$scope',function($scope){
    $scope.toogleRN=true;

    $scope.toogleIt= function()
    {
        $scope.toogleRN = !$scope.toogleRN;
        console.log($scope.toogleRN);
    };

    $scope.allRows=[{name:'Name_1',age:25},
                    {name:'Name_2',age:28},
                    {name:'Name_3',age:17},
                    {name:'Name_4',age:25},
                    {name:'Name_5',age:26}];
}]);


默认情况下,需求第一行应为只读,单击“编辑”按钮时应可编辑。通过使用以上代码,它完全满足了我的要求,但是我的问题是如何将ng-readonly="toogleRN && $first"移至控制器?

最佳答案

使用功能:

ng-readonly="myFunction(toogleRN, $first, row.editable)"
// on the button
 ng-click = row.editable = true
 // in the javascript
 $scope.myFunction = function(toogleRN, isFirt, isEditable){

 }

09-30 16:34
查看更多