forked from bennadel/JavaScript-Demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.htm
87 lines (60 loc) · 1.82 KB
/
new.htm
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
86
87
<!doctype html>
<html ng-app="Demo">
<head>
<meta charset="utf-8" />
<title>
Looking At Attribute Interpolation Workflow In AngularJS 1.2.16
</title>
</head>
<body ng-controller="AppController">
<h1>
Looking At Attribute Interpolation Workflow In AngularJS 1.2.16
</h1>
<!-- Here, wer are using a Directive that uses attribute interpolation. -->
<p bn-title="My friend is {{ friend }}.">
This is a directive.
</p>
<!-- Load scripts. -->
<script type="text/javascript" src="../../vendor/jquery/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../../vendor/angularjs/angular-1.2.16.min.js"></script>
<script type="text/javascript">
// Create an application module for our demo.
var app = angular.module( "Demo", [] );
// -------------------------------------------------- //
// -------------------------------------------------- //
// I control the root of the application.
app.controller(
"AppController",
function( $scope, $parse ) {
$scope.friend = "Sarah";
}
);
// -------------------------------------------------- //
// -------------------------------------------------- //
// I am the directive that tests the attribute interpolation to see when the
// interpolated value is available to the link function.
app.directive(
"bnTitle",
function() {
// I bind the JavaScript events to the scope.
function link( $scope, element, attributes ) {
// Check initial value.
console.log( "On link load:", attributes.bnTitle );
// Watch the value over time.
attributes.$observe(
"bnTitle",
function( newValue, oldValue ) {
console.log( "On observe:", newValue );
}
);
}
// Return the directive configuration.
return({
link: link,
restrict: "A"
});
}
);
</script>
</body>
</html>