不能使用Angular.js动态启用文本字段

Can not enable text field dynamically using Angular.js

本文关键字:启用 文本 字段 动态 js Angular 不能      更新时间:2023-09-26

我有一个问题。我需要启用我的文本字段动态使用angular.js,但它没有发生。我在下面解释我的代码。

<tr ng-repeat="gl in galleryDatas">
<td><input type="checkbox" ng-change="clickedRow(gl.checked,$index)" name="" ng-model="gl.checked"> {{$index+1}}</td>
<td><img ng-src="upload/{{gl.image}}" border="0" name="image" style="width:100px; height:100px;" /></td>
<td><textarea id="address" name="desc" class="form-control oditek-form" placeholder="Add comment" rows="6" ng-model="gl.description" style="height:70px" ng-readonly="gl.galComnt"></textarea></td>
<td>
<a class="btn btn-xs btn-success" title="Edit" ng-click="editComment(gl.gallery_id,$index,gl.description)"><i class="fa fa-pencil-square-o fa-fw"></i>{{gl.galEDit}}</a>
</td>
</tr>

控制器端代码如下:

$http({
                method:'POST',
                url:"php/customerInfo.php",
                data:imageData,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).then(function successCallback(response){
                $scope.formDiv=false;
                $scope.gallery=true;
                $scope.galleryDatas=[];
                for(var i=0;i<response.data.length;i++){
                    var data={'gallery_id':response.data[i].    gallery_id,'subcat_id':response.data[i].subcat_id,'image':response.data[i].image,'description':response.data[i].description,'galComnt':true,'galEDit':"Edit"};
                    $scope.galleryDatas.push(data);
                }
            }

在这里我需要,而用户将点击编辑按钮,各自的行描述字段将是可编辑的。我的代码如下:

$scope.editComment=function(galid,index,comnt){
        if($scope.galleryDatas[index].galEDit=="Edit"){
            $scope.galleryDatas[index].galEDit="Update";
            $scope.galleryDatas[index].galComnt=false;
        }
}

但是这里不起作用。在这里,我需要而用户将点击任何行编辑按钮,各自的行文本区域将是可编辑的。

你不应该玩index,最终会混乱(甚至更多,当你使用更多的过滤器对ng-repeat),而不是只是传递一个gl对象到editComment函数。无论你在对象中做了什么改变,都会反射到它的原始引用和视图中。

ng-click="editComment(gl)"

$scope.editComment=function(gl){
    if(gl.galEDit=="Edit"){
        gl.galEDit="Update";
        gl.galComnt=false;
    }
}

clickedRow函数执行相同的操作