--@angularJS--简单的带嵌套的指令demo

时间:2015-05-19 18:26:10   收藏:0   阅读:2099

<!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>
</head>
<body>
<!-- 下面是带嵌套的自定义指令demo. -->
<div>
    <hello>Lucy</hello>
</div>
<script>
var myModule = angular.module("app",[]);
myModule.directive(‘hello‘,function(){
    return {
        restrict:‘AE‘,
        replace:true,
        transclude:true,
        template:‘<div>Hi there <span ng-transclude></span></div>‘
    }
});//如果声明了模板,而html中还有嵌套内容的话,就必须用<span ng-transclude></span>指定其嵌套的位置,并声明transclude:true,这个属性为true,否则嵌套内容不会显示
</script>
</body>
</html>

原文:http://www.cnblogs.com/koleyang/p/4515074.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!