-
Notifications
You must be signed in to change notification settings - Fork 1
/
directives.html
52 lines (48 loc) · 1.61 KB
/
directives.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
<!DOCTYPE HTML>
<html ng-app='Myevents'>
<head>
<title>Hello</title>
</head>
<body>
<div ng-controller="myController">
<label>Total Event: {{events.length}}</label><br>
<label>Remaining Event: {{remaining()}}</label>
<ul class="unstyled">
<li ng-repeat="event in events" enter="{{event.name}}">
<input type="checkbox" ng-model="event.done">{{ event.name }}
</li>
</ul>
<input type="text" ng-model="newEvent" placeholder="Enter event name">
<button ng-click="addEvent()">Add Event</button>
</div>
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.7/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('Myevents', []);
app.controller('myController', function($scope){
$scope.events = [
{'name':'Event 1', 'done': false},
{'name':'Event 2', 'done': false},
{'name':'Event 3', 'done': false}
];
$scope.addEvent = function(){
$scope.events.push({'name':$scope.newEvent, 'done': false});
}
$scope.remaining = function() {
var count = 0;
angular.forEach($scope.events, function(event) {
count += event.done ? 0 : 1;
});
return count;
};
});
app.directive('enter', function(){
return function(scope, element, attr){
element.bind('mouseenter', function(){
console.log('Event: '+attr.enter+ ' === Status: '+(scope.event.done?"Done":"Not Done"));
});
}
});
</script>
</body>
</html>