<!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></hello>
</div>
<script>
var myModule = angular.module("app",[]);
myModule.directive(‘hello‘,function(){//声明一个指令hello标签,替换它的模板是<div>Hi there</div>.反过来也可以说是hello标签表示<div>Hi there</div>这一串html模板代码
return {
restrict:‘AE‘,
replace:true,
template:‘<div>Hi there</div>‘
}
});
</script>
</body>
</html>
时间: 2024-10-15 18:11:17