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

 运行结果 
 北美留学生论坛