如何根据angularjs中的模型条件隐藏和显示div?

如何根据angularjs中的模型条件隐藏和显示div?,angularjs,Angularjs,我想根据复选框隐藏/显示div。看起来很简单。我将checkbox的值存储在模型中,并在div ng show中使用它。我做错了什么 <div ng-app='visibleApp'> <div ng-controller='myController'> <input type="checkbox" name="hideBasicInfo" ng-model="hideBasicInfo">hide the basic informa

我想根据复选框隐藏/显示div。看起来很简单。我将checkbox的值存储在模型中,并在div ng show中使用它。我做错了什么

<div ng-app='visibleApp'>
    <div ng-controller='myController'>
         <input type="checkbox" name="hideBasicInfo" ng-model="hideBasicInfo">hide the basic information section
         <div ng-show="{{!hideBasicInfo}}">
             <label for="firstName">First Name:</label>
             <input type="text" name="firstName" ng-model="firstName"/></br>

             <label for="middleName">Middle Name:</label>
             <input type="text" name="middleName" ng-model="middleName"/></br>
             <label for="lastName">Last Name:</label>
             <input type="text" name="lastName" ng-model="lastName"/>
         </div>
         <hr/>
         <div>
             <h4>Debug Information</h4>
             hideBasicInfo: {{hideBasicInfo}}<br/>
             !hideBasicInfo: {{!hideBasicInfo}}
         </div>
     </div>
</div>
多谢各位

请看

几乎就在那里

 <div ng-hide="hideBasicInfo">
    ...
 </div>

...
不需要模板大括号({{})。


第一节

第二节

第三节

执行此代码:`在此处输入代码`
1.显示
显示正方形:


2.隐藏 隐藏正方形:

您不需要{{}谢谢您的回答。也许一个解释会让解决方案更明显?只需运行下面的代码,1。显示正方形:



2。隐藏正方形:
ngShow指令根据提供给ngShow属性的表达式显示或隐藏给定的HTML元素。通过在元素上删除或添加.ng hide CSS类来显示或隐藏元素。.ng hide CSS类在AngularJS中预定义,并将显示样式设置为none(使用!重要标志)。对于CSP模式,请将angular-CSP.css添加到您的html文件中(请参阅ngCsp)。尽管代码很受欢迎,但它应该始终附带说明。这不需要很长时间,但这是意料之中的。
 <div ng-hide="hideBasicInfo">
    ...
 </div>
<div ng-show='One'>
 <p>Section One</p>
</div>

<div ng-show='Two'>
 <p>Section Two</p>
</div>

<div ng-show='Three'>
 <p>Section Three</p>
</div>

<!-- Navigation -->
<nav>
 <a href='#' ng-click='showOne'> Show Div One </a>
 <a href='#' ng-click='showTwo'> Show Div Two </a>
 <a href='#' ng-click='showThree'> Show Div Three </a>
</nav>
Execute this code:`enter code here`
<!DOCTYPE html>
<html>
<head>
  <script src="angular.js"></script>
</head>

<body ng-app>
  <h3>1. Show</h3>
  <label>Show the square: <input type="checkbox" ng-model="mustShow" /></label><br />
  <div ng-show="mustShow" style="width: 50px; height: 50px; background-color: red;"></div><br />
  <br />
  <h3>2. Hide</h3>
  <label>Hide the square: <input type="checkbox" ng-model="mustHide" /></label><br />
  <div ng-hide="mustHide" style="width: 50px; height: 50px; background-color: green;"></div>
</body>
</html>