简体   繁体   English

无法使用Angular.js动态启用文本字段

[英]Can not enable text field dynamically using Angular.js

I have an issue.I need to enable my text field dynamically using angular.js but its not happening. 我有一个问题。我需要使用angular.js动态启用我的文本字段,但它没有发生。 I am explaining my code below. 我在下面解释我的代码。

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

My controller side code is given below. 我的控制器端代码如下。

$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);
                }
            }

Here i need while user will click on edit button the respective row description field will be editable. 在这里,我需要用户点击编辑按钮,相应的行描述字段将是可编辑的。 My code is given below. 我的代码如下。

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

But here its not working. 但这里没有用。 Here i need while user will click on any row edit button,the respective row text area will be editable.Please help me. 在这里我需要用户点击任何行编辑按钮,相应的行文本区域将是可编辑的。请帮助我。

You should not be playing with index that will end up with mess(even more when you use more filters on ng-repeat ), instead just pass an gl object to editComment function. 您不应该使用最终会出现混乱的index (当您在ng-repeat上使用更多过滤器时更多),而只是将gl对象传递给editComment函数。 Whatever you change in the object will reflect to it original reference and on view as well. 无论你在对象中改变什么,都会反映它的原始参考和视图。

ng-click="editComment(gl)"

Code

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

Follow the same thing for clickedRow function. clickedRow函数执行相同的clickedRow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM