如何根据angularjs中的模型条件隐藏和显示div?
发布时间:2020-12-17 07:32:57 所属栏目:安全 来源:网络整理
导读:我想基于复选框隐藏/显示div.看起来很简单.我将复选框的值存储在模型中并在div ng-show中使用它.我究竟做错了什么? div ng-app='visibleApp' div ng-controller='myController' input type="checkbox" name="hideBasicInfo" ng-model="hideBasicInfo"hide t
|
我想基于复选框隐藏/显示div.看起来很简单.我将复选框的值存储在模型中并在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>
JS档案: var visibleApp = angular.module('visibleApp',[]);
visibleApp.controller('myController',function($scope){
$scope.data = "my data";
$scope.hideBasicInfo = false;
});
谢谢. 见fiddle
差不多了…
<div ng-hide="hideBasicInfo">
...
</div>
不需要模板括号({{}}). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
