javascript - 使用 angularjs 显示/隐藏级联 tr

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

Controller 就像,

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

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

最佳答案

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

关于javascript - 使用 angularjs 显示/隐藏级联 tr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51552681/

相关文章:

javascript - 如何根据从三个子 Controller 获得的结果在父 Controller 中显示动态消息

javascript - 使用 axios 递归获取数据并链接结果

javascript - 将属性 "innerHTML"设置为 null

javascript - 菜单选项卡按钮不起作用

javascript - 按照 SlideDown() 的方式计算元素高度

javascript - 如何通过.js将json数据加载到html

javascript - 如何在 AngularJS 中发送 HTTP 请求 onbeforeunload?

javascript - 没有图像或其他元素的 document.onload(仅 HTML)

angularjs - 如果设置了特定的 header ,则测试 AngularJs 的 $http.defaults.headers.common

angularjs - 注入(inject) $state (ui-router) 导致循环依赖