--@angularJS--较复杂的指令嵌套demo——综合小实例:登陆界面
1、index.html:
<!DOCTYPE HTML>
<html ng-app="app">
<head>
<title>custom-directive</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.css">
<script src="../js/angular.js"></script>
<style>
.wrapper{
border-radius:6px;
width:500px;
height:auto;
background:#f2f2f2;
padding:50px 40px 30px 40px;
margin:0 auto;
margin-top:120px;
box-shadow:0 0 6px #333;
}
.btn_diff{
width:100px;
margin-right:15px;
position:relative;
left:160px;
}
</style>
</head>
<body>
<!-- 下面是带嵌套的自定义指令demo. -->
<div class="wrapper">
<form class="form-horizontal" role="form">
<control>用户名:</control>
<br>
<controlpwd>密码:</controlpwd>
<br>
<controlbtn>登录</controlbtn>
<controlbtn>取消</controlbtn>
</form>
</div>
<script src="./directive-form.js"></script>
</body>
</html>
2、directive-form.js:
var myModule = angular.module("app",[]);
myModule.directive(‘control‘,function(){//自定义可复用B3风格文本输入框
return {
restrict:‘AE‘,
replace:true,
transclude:true,
scope:{},
link:function(scope,element,attrs){
},
template:‘<div class="form-group"><label class="col-md-2 control-label"><span ng-transclude></span></label><div class="col-md-10"><input class="form-control" type="text" placeholder="请输入用户名..."></div></div>‘
}
}).directive(‘controlpwd‘,function(){//自定义可复用B3风格密码输入框
return {
restrict:‘AE‘,
replace:true,
transclude:true,
scope:{},
link:function(scope,element,attrs){
},
template:‘<div class="form-group"><label class="col-md-2 control-label"><span ng-transclude></span></label><div class="col-md-10"><input class="form-control" type="password" placeholder="请输入密码..."></div></div>‘
}
}).directive(‘controlbtn‘,function(){//自定义可复用B3风格按钮
return {
restrict:‘AE‘,
replace:true,
transclude:true,
template:‘<button class="btn btn-default btn_diff"><span ng-transclude></span></button>‘
}
});
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。