案例:AngularJS案例     状态:可编辑再运行    进入横版
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<script src="/js/angular.js1.4.6/angular.min.js"></script> 
6
</head>
7
<body ng-app="myApp">
8
9
<div class="w3xue-directive"></div>
10
11
<script>
12
var app = angular.module("myApp", []);
13
app.directive("w3xueDirective", function() {
14
    return {
15
        restrict : "C",
16
        template : "<h1>自定义指令!</h1>"
17
    };
18
});
19
</script>
20
21
<p><strong>注意:</strong> 你必须设置 <b>restrict</b> 的值为 "C" 才能通过类名来调用指令。</p>
22
23
</body>
24
</html>

 运行结果 
 北美留学生论坛