<!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>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-01-21
  • 2022-01-19
  • 2022-12-23
  • 2021-10-18
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
相关资源
相似解决方案