1
+ <!doctype html>
2
+ < html ng-app ="Demo ">
3
+ < head >
4
+ < meta charset ="utf-8 " />
5
+
6
+ < title >
7
+ Inspecting Attribute-Normalization Within Directives In AngularJS
8
+ </ title >
9
+ </ head >
10
+ < body >
11
+
12
+ < h1 >
13
+ Inspecting Attribute-Normalization Within Directives In AngularJS
14
+ </ h1 >
15
+
16
+ < p
17
+ bn-one ="Some value. "
18
+ data-bn-two ="Some value. "
19
+ x-bn-three ="Some value. "
20
+ bn:four ="Some value. ">
21
+ This is my directive!
22
+ </ p >
23
+
24
+
25
+ <!-- Load scripts. -->
26
+ < script type ="text/javascript " src ="../../vendor/jquery/jquery-2.1.0.min.js "> </ script >
27
+ < script type ="text/javascript " src ="../../vendor/angularjs/angular-1.2.16.min.js "> </ script >
28
+ < script type ="text/javascript ">
29
+
30
+ // Create an application module for our demo.
31
+ var app = angular . module ( "Demo" , [ ] ) ;
32
+
33
+
34
+ // -------------------------------------------------- //
35
+ // -------------------------------------------------- //
36
+
37
+
38
+ // Define each of our directives - they all use the same logic.
39
+ angular . forEach (
40
+ [ "bnOne" , "bnTwo" , "bnThree" , "bnFour" ] ,
41
+ function ( hook ) {
42
+
43
+ app . directive (
44
+ hook ,
45
+ function ( ) {
46
+
47
+ function link ( $scope , element , attributes ) {
48
+
49
+ // The [attributes] collection is keyed on the normalized
50
+ // value of the directive. But, it contains the $attr
51
+ // collection, which maps the normalized value to the actual
52
+ // attribute notation defined by the developer.
53
+ console . log (
54
+ "%s defined as %c %s " ,
55
+ hook ,
56
+ "background-color: yellow; font-weight: bold ;" ,
57
+ attributes . $attr [ hook ]
58
+ ) ;
59
+
60
+ }
61
+
62
+ // Return the directive configuration.
63
+ return ( {
64
+ link : link
65
+ } ) ;
66
+
67
+ }
68
+ ) ;
69
+
70
+ }
71
+ ) ;
72
+
73
+ </ script >
74
+
75
+ </ body >
76
+ </ html >
0 commit comments