This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
directive.html
85 lines (75 loc) · 2.29 KB
/
directive.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>Directive - AngularJS Test</title>
<style type="text/css">
.test-div {margin:15px;padding:15px;border:1px solid #ccc;}
</style>
</head>
<body>
<div class="test-div">
<ul ng-init="users=[{firstName:'Neo',lastName:'Huang'},{firstName:'Shelly',lastName:'Lee'}]">
<li ng-repeat="user in users">
<p ng-if="$even" style="color:red;">{{$index+1}} : {{user.firstName + " " + user.lastName}}</p>
<p ng-if="$odd" style="color:blue;">{{$index+1}} : {{user.firstName + " " + user.lastName}}</p>
</li>
</ul>
</div>
<div class="test-div">
<my-test-directive></my-test-directive>
</div>
<div class="test-div">
<p my-test-directive></p>
</div>
<div class="test-div">
<p class="my-test-directive"></p>
</div>
<div class="test-div">
<!-- directive: my-test-directive -->
</div>
<script type="text/javascript" src="static/js/angular-1.5.8.js"></script>
<script type="text/javascript">
/**
* AngularJS lets you extend HTML with new attributes called Directives.
* AngularJS has a set of built-in directives which offers functionality to your applications.
* AngularJS also lets you define your own directives.
* AngularJS directives are extended HTML attributes with the prefix ng-
*/
/**
* Common Built-in Directives:
* ng-app
* ng-init
* ng-bind
* ng-controller
* ng-model
* ng-repeat
* ng-click
* ng-src
* ...
*/
/**
* Create New Directive:
* New directives are created by using the .directive function.
* When naming a directive, you must use a camel case name, myTestDirective,
* but when invoking it, you must use - separated name, my-test-directive
*/
/**
* Invoke a directive by using:
* E: Element name
* A: Attribute
* C: Class
* M: Comment
*/
var myApp = angular.module("myApp", []);
myApp.directive("myTestDirective", function() {
return {
restrict: "A", //default: EA
//replace: true, //false: the comment would be invisible
template: "<h3>Hello Directive</h3>"
};
});
</script>
</body>
</html>