-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirective-1.html
More file actions
42 lines (38 loc) · 1 KB
/
directive-1.html
File metadata and controls
42 lines (38 loc) · 1 KB
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
<!DOCTYPE html>
<html ng-app='myapp' >
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<script>
var app = angular.module('myapp', []);
app.directive('helloWorld', function(){
return {
scope: {
color: '@colorAttr'
},
restrict:'AE',
replace: true,
template: '<p style="background-color:{{color}};">Hello World!</p>',
link: function(scope, elem, attrs) {
elem.bind('click', function() {
elem.css('background-color', 'white');
scope.$apply(function() {
scope.color = "white";
});
});
elem.bind('mouseover', function(){
elem.css('cursor', 'pointer');
});
}
};
});
</script>
</head>
<body>
<input type="text" ng-model='color' placeholder='Enter a color' />
<hello-world color-attr="{{color}}"></hello-world>
</body>
</html>