Skip to content

Commit 0298c42

Browse files
committed
Add empty collection.
1 parent 5d14d36 commit 0298c42

File tree

1 file changed

+47
-4
lines changed
  • demos/ng-repeat-complete-event-angularjs

1 file changed

+47
-4
lines changed

demos/ng-repeat-complete-event-angularjs/index.htm

+47-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ <h1>
2222
Hooking Into The ngRepeat Completion Event In AngularJS
2323
</h1>
2424

25+
26+
<h3>
27+
Friends
28+
</h3>
29+
2530
<ul>
2631
<!--
2732
When the ngRepeat finishes its first round of rendering,
@@ -43,6 +48,31 @@ <h1>
4348
</p>
4449

4550

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+
4676
<!-- Load scripts. -->
4777
<script type="text/javascript" src="../../vendor/jquery/jquery-2.0.3.min.js"></script>
4878
<script type="text/javascript" src="../../vendor/angularjs/angular-1.2.min.js"></script>
@@ -61,7 +91,6 @@ <h1>
6191
"AppController",
6292
function( $scope ) {
6393

64-
6594
// Define the collection of friends to render.
6695
$scope.friends = [
6796
{
@@ -75,15 +104,29 @@ <h1>
75104
}
76105
];
77106

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+
78113

79114
// ---
80115
// PUBLIC METHODS.
81116
// ---
82117

83118

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.
87130
$scope.addFriend = function() {
88131

89132
$scope.friends.push({

0 commit comments

Comments
 (0)