Priya
Priya

Reputation: 31

Show/hide cascading tr using angularjs

I am trying to show/hide on button click. I tried,

    <tr>
        <td colspan="2">
            <button ng-click="visible = true">Calibration</button>
        </td>

        <td colspan="2"> Offsset                
        </td>

        <td colspan="3" > Multiplier
        </td>

    </tr>

    <tr ng-if="visible" >  
       <td colspan="5">
         True value:
       </td>                                                                                                     
       <td colspan="2">         
         <button ng-click="visible = false">Cancel</button>
         <button ng-click="visible1 = true">OK</button>
       </td>
   </tr>

   <tr  ng-if="visible1" >  
     <td colspan="5" >
     True value: <input type="text" name="val1" id="val1" style="width:50%"/>
     </td>
     <td colspan="2">   
         <button ng-click="visible1 = false" >Cancel</button>
         <button> OK </button>
     </td>
</tr>

controller is like,

$scope.visible = false;
$scope.visible1 = false;

issue is that calibration button works.But another ok cancel buttons are not working.

Upvotes: 0

Views: 57

Answers (1)

ACT
ACT

Reputation: 159

use ng-show in place of ng-if

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<table>
<tr>
        <td colspan="2">
            <button ng-click="visible = true">Calibration</button>
        </td>

        <td colspan="2"> Offsset                
        </td>

        <td colspan="3" > Multiplier
        </td>

    </tr>

    <tr ng-show="visible" >  
       <td colspan="5">
         True value:
       </td>                                                                                                     
       <td colspan="2">   
       <div>
         <button ng-click="visible = false">Cancel</button>
         <button ng-click="visible1 = true">OK</button>
         </div>
       </td>
   </tr>

   <tr  ng-show="visible1" >  
     <td colspan="5" >
     True value: <input type="text" name="val1" id="val1" style="width:50%"/>
     </td>
     <td colspan="2">   
         <button ng-click="visible1 = false" >Cancel</button>
         <button> OK </button>
     </td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
   $scope.visible = false;
$scope.visible1 = false;   
});
</script>

<p>Use the ng-bind directive to bind the innerHTML of an element to a property in the data model.</p>

</body>
</html>

Upvotes: 1

Related Questions