使用angularjs显示/隐藏级联tr

时间:2018-07-27 07:15:53

标签: javascript angularjs

我试图显示/隐藏按钮单击。 我尝试过,

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

控制器就像

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

问题是校准按钮有效。但是另一个确定取消按钮不起作用。

1 个答案:

答案 0 :(得分:1)

使用ng-show代替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>