共同点: 都是判断性的指令,里边可以是简单的表达式,返回结果是布尔类型的值
不同点:
<!DOCTYPE html>
<html lang="en" ng-app="myapp">
<head>
<meta charset="UTF-8">
<title>ng-if与ng-show</title>
<style type="text/css">
section{text-align: center;}
div{
background-color: gold;
width:100px;
height:100px;
margin:0 auto;
}
</style>
</head>
<body>
<section ng-controller="MainCtrl as mainctrl">
<input type="button" value="按我" ng-click="mainctrl.changeShow()">
<div ng-controller="SubCtrl as subctrl" ng-show="mainctrl.isShow">你好</div>
</section>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript">
//创建一个module
var myapp = angular.module("myapp",[]);
//控制器
myapp.controller("MainCtrl",[function(){
this.isShow = true;
var self = this;
this.changeShow = function(){
self.isShow = !self.isShow;
}
}]);
myapp.controller("SubCtrl",[function(){
alert("我是SubCtrl,我被实例化了!");
}]);
</script>
</body>
</html>
我是SubCtrl,我被实例化了!