angular的几种元素隐藏的方式

来源:互联网 发布:aⅴ淘宝新址 编辑:程序博客网 时间:2024/05/22 02:15

ng-show和ng-if 等几个隐藏显示元素的方法。

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="UTF-8">  
  5.         <title></title>  
  6.         <script src="day2/src/angular.js"></script>  
  7.         <style type="text/css">  
  8.             .box{  
  9.                 width: 100px; height: 100px; background: red;  
  10.             }  
  11.               
  12.         </style>  
  13.     </head>  
  14.     <body>  
  15.           
  16.         <div ng-app="fristApp">  
  17.             <div ng-controller="fristController">  
  18.                 <!--show方法吧display设置成none 不显示的时候在dom中-->  
  19.                 <div class="box"ng-show="isShow"></div>  
  20.                 <div class="box" ng-hide="isShow"></div>  
  21.                   
  22.                 <!--if隐藏就不存在dom中-->  
  23.                 <div class="box"ng-if="isShow"></div>  
  24.                   
  25.                 <!--定义一个开关,只有当父div中子元素的相应变量值等于current时才会显示,  
  26.                 其他的都会隐藏(在dom中不存在)-->  
  27.                 <div ng-switch on="current">  
  28.                     <div ng-switch-when="home">home</div>  
  29.                     <div ng-switch-when="home1">home1</div>  
  30.                     <div ng-switch-when="home2">home2</div>  
  31.                 </div>  
  32.             </div>  
  33.             </div>  
  34.               
  35.         </div>  
  36.     </body>  
  37.     <script type="text/javascript">  
  38.         var myApp = angular.module('fristApp',[]);  
  39.         myApp.controller('fristController',function($scope){  
  40.             $scope.isShow = true;  
  41.             $scope.current = "home2"  
  42.         })  
  43.     </script>  
  44. </html>  
0 0
原创粉丝点击