File tree 1 file changed +47
-4
lines changed
demos/ng-repeat-complete-event-angularjs
1 file changed +47
-4
lines changed Original file line number Diff line number Diff line change 22
22
Hooking Into The ngRepeat Completion Event In AngularJS
23
23
</ h1 >
24
24
25
+
26
+ < h3 >
27
+ Friends
28
+ </ h3 >
29
+
25
30
< ul >
26
31
<!--
27
32
When the ngRepeat finishes its first round of rendering,
43
48
</ p >
44
49
45
50
51
+ < h3 >
52
+ Enemies
53
+ </ h3 >
54
+
55
+ < ul >
56
+ <!--
57
+ When the ngRepeat finishes its first round of rendering,
58
+ we're going to invoke the doSomething() callback.
59
+ -->
60
+ < li
61
+ ng-repeat ="enemy in enemies "
62
+ repeat-complete ="doSomething( $index ) ">
63
+
64
+ {{ enemy.name }}
65
+
66
+ </ li >
67
+ </ ul >
68
+
69
+ < p >
70
+ < a ng-click ="addEnemy() "> Add Enemy</ a >
71
+ -
72
+ < em > This WILL trigger one more "complete" event</ em > .
73
+ </ p >
74
+
75
+
46
76
<!-- Load scripts. -->
47
77
< script type ="text/javascript " src ="../../vendor/jquery/jquery-2.0.3.min.js "> </ script >
48
78
< script type ="text/javascript " src ="../../vendor/angularjs/angular-1.2.min.js "> </ script >
61
91
"AppController" ,
62
92
function ( $scope ) {
63
93
64
-
65
94
// Define the collection of friends to render.
66
95
$scope . friends = [
67
96
{
@@ -75,15 +104,29 @@ <h1>
75
104
}
76
105
] ;
77
106
107
+ // Define the collection of enemies to render. This
108
+ // collection will start out empty in order to demonstrate
109
+ // that this approach requires at least ONE element to
110
+ // render.
111
+ $scope . enemies = [ ] ;
112
+
78
113
79
114
// ---
80
115
// PUBLIC METHODS.
81
116
// ---
82
117
83
118
84
- // I add a new friend to the collection - this is done
85
- // to demonstrate that as new items are rendered, we
86
- // do NOT re-invoke the complete handler.
119
+ // I add a new enemty to the collection.
120
+ $scope . addEnemy = function ( ) {
121
+
122
+ $scope . enemies . push ( {
123
+ name : "Banana"
124
+ } ) ;
125
+
126
+ }
127
+
128
+
129
+ // I add a new friend to the collection.
87
130
$scope . addFriend = function ( ) {
88
131
89
132
$scope . friends . push ( {
You can’t perform that action at this time.
0 commit comments