-
Notifications
You must be signed in to change notification settings - Fork 7
/
demo.html
65 lines (48 loc) · 1.69 KB
/
demo.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
53
54
55
56
57
58
59
60
61
62
63
64
65
<html ng-app="test">
<head>
<!-- // <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular.js"></script>
<script src="angular-360-no-scope.js"></script>
<script>
var app = angular.module('test', ['angular-360-no-scope']);
app.controller('MyController', function($log) {
var ctrl = this;
ctrl.watchCount = 0;
ctrl.watchCollectionCount = 0;
ctrl.logEvent = $log.log;
ctrl.$watch('foo.bar.baz', function incrementWatchCount() {
this.watchCount++;
this.$emit('customEvent', 'watchCount', this.watchCount);
});
ctrl.$watchCollection('foo.bar.baz', function incrementWatchCollectionCount() {
this.watchCollectionCount++;
this.$emit('customEvent', 'watchCollectionCount', this.watchCollectionCount);
});
ctrl.$on('customEvent', function logEvent(event, name, count) {
this.logEvent(name, count);
});
});
app.run(function($rootScope) {
// $rootScope.$on('customEvent', function(event, count) { console.log(event, count); });
});
</script>
</head>
<body ng-controller="MyController as ctrl">
<h1>angular-360-no-scope</h1>
<form>
<label>
Input:
<input type="text" ng-model="ctrl.foo.bar.baz">
</label>
<button>Submit</button>
</form>
<ul>
<li>
The $watch has been invoked {{ ctrl.watchCount }} times.
</li>
<li>
The $watchCollection has been invoked {{ ctrl.watchCollectionCount }} times.
</li>
</ul>
</body>
</html>