3

Below is my Code.

var myfriend = angular.module('myfriend',[]);

myfriend.controller('myfriendController', function($scope) 
{
   $scope.record = [
       {     "id" : "01",
            "firstname" : "Mohan ",
            "middlename" : "K",
            "lastname" : "Futterkiste1"
        },{
             "id" : "04",
            "firstname" : "Rohan ",
            "middlename" : "A",
            "lastname" : "Futterkiste2"
        },{
              "id" : "08",
            "firstname" : "sohan ",
            "middlename" : "M",
            "lastname" : "Futterkiste3"
        }
   ]
  
                   
});
<html>
  <head>
          <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>

  </head>
  <body ng-app="myfriend">
    
        
    
    <table class="table" style="border:1px red solid; width:100%; "  ng-controller="myfriendController">
      <thead>
        <tr>
         <th>Id</th>
          <th>First name</th>
          <th>Middle name</th>
             <th>Last name</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="x in record">
             <th>{{x.id}}</th>
             <th><input type="text" ng-value="x.firstname"></th>
                <th><input type="text" ng-value="x.middlename"></th>
                <th><input type="text" ng-value="x.lastname"></th>
        </tr>
              <tr>
                <td><button> Submit</button></td>
              </tr>
      </tbody>  
 </table> 
  <body>
</html>

What I want is on click of submit button, it should disabled the field of Rohan only(Rohan is coming through ng-repeat).I want to achieve this through ng-disabled in ng-if.

Help me for this.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Mohammed
  • 648
  • 2
  • 12
  • 32

2 Answers2

3

You can by doing this

<tr ng-repeat="x in record">
   <th>{{x.id}}</th>
   <th><input type="text" ng-model="x.firstname" ng-disabled="x.disabled" value="x.firstname"></th>
   <th><input type="text" ng-model="x.middlename"  value="x.middlename"></th>
   <th><input type="text" ng-model="x.lastname" value="x.lastname"></th>
</tr>

Controller

Just add disabled attribute to 'Rohan' after submit

var myfriend = angular.module('myfriend',[]);

myfriend.controller('myfriendController', function($scope) 
{

   $scope.record = [
       {     "id" : "01",
            "firstname" : "Mohan",
            "middlename" : "K",
            "lastname" : "Futterkiste1"
        },{
             "id" : "04",
            "firstname" : "Rohan",
            "middlename" : "A",
            "lastname" : "Futterkiste2"
        },{
              "id" : "08",
            "firstname" : "sohan",
            "middlename" : "M",
            "lastname" : "Futterkiste3"
        }
   ]

   $scope.submit = function () {
       angular.forEach($scope.record, function (v) {
          if (v.firstname === 'Rohan') {
              v.disabled = true;
           }
       });
       console.log($scope.record);
   }


});

Working fiddle: JsFiddle

digit
  • 4,479
  • 3
  • 24
  • 43
1

I think, thing is not possible, because ng-if delete the html tags. Like

<div ng-if="error">
      <input type="text" ng-disabled="disable">
</div>

its means inside tag div nothing will load in dom if error == true; so ng-disable is no available in this case.

  • actually, in my case, there is 7 different section and in seven different section there is seven different input box. so what I want is if I click on second section then in second section's submit button then particularly that sections input field should be disabled. but currently All sections input field is disabling. @Yuvraj Singh – Mohammed Jan 20 '17 at 12:00