-
Notifications
You must be signed in to change notification settings - Fork 0
/
exemplo 8.1 – eventos.html
43 lines (39 loc) · 1.19 KB
/
exemplo 8.1 – eventos.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
<!doctype html>
<html ng-app="myApp">
<body>
<div ng-controller="TopController">
TopController count: {{count}}
<div ng-controller="MiddleController">
<b>MiddleController count: {{count}}</b>
<button ng-click="$emit('MyEvent')">$emit('MyEvent') from MiddleController $scope</button>
<button ng-click="$broadcast('MyEvent')">$broadcast('MyEvent') from MiddleController $scope</button>
<br>
<div ng-controller="BottomController">
BottomController count: {{count}}
</div>
</div>
</div>
<script src="angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('TopController', [ '$scope', function($scope) {
$scope.count = 0;
$scope.$on('MyEvent', function() {
$scope.count++;
});
} ]);
app.controller('MiddleController', [ '$scope', function($scope) {
$scope.count = 0;
$scope.$on('MyEvent', function() {
$scope.count++;
});
} ]);
app.controller('BottomController', [ '$scope', function($scope) {
$scope.count = 0;
$scope.$on('MyEvent', function() {
$scope.count++;
});
}]);
</script>
</body>
</html>