Skip to content

Commit 082f754

Browse files
committed
Add attr example.
1 parent 53beb09 commit 082f754

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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>

index.htm

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ <h1>
1313
</h1>
1414

1515
<ul>
16+
<li>
17+
<a href="./demos/inspecting-attribute-normalization-directives-angularjs/">Inspecting Attribute-Normalization Within Directives In AngularJS</a>
18+
</li>
1619
<li>
1720
<a href="./demos/shadowing-isolate-scope-behaviors-angularjs/">Shadowing Isolate Scope Behaviors In AngularJS</a>
1821
</li>

0 commit comments

Comments
 (0)