100
100
* For example: `item in items` is equivalent to `item in items track by $id(item)`. This implies that the DOM elements
101
101
* will be associated by item identity in the array.
102
102
*
103
+ * * `variable in expression as alias_expression` – You can also provide an optional alias expression which will then store the
104
+ * intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message
105
+ * when a filter is active on the repeater, but the filtered result set is empty.
106
+ *
107
+ * For example: `item in items | filter:x as results` will store the fragment of the repeated items as `results`, but only after
108
+ * the items have been processed through the filter.
109
+ *
103
110
* For example: `item in items track by $id(item)`. A built in `$id()` function can be used to assign a unique
104
111
* `$$hashKey` property to each item in the array. This property is then used as a key to associated DOM elements
105
112
* with the corresponding item in the array by identity. Moving the same object in array would move the DOM
132
139
I have {{friends.length}} friends. They are:
133
140
<input type="search" ng-model="q" placeholder="filter friends..." />
134
141
<ul class="example-animate-container">
135
- <li class="animate-repeat" ng-repeat="friend in friends | filter:q">
142
+ <li class="animate-repeat" ng-repeat="friend in friends | filter:q as results ">
136
143
[{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
137
144
</li>
145
+ <li class="animate-repeat" ng-if="results.length == 0">
146
+ <strong>No results found...</strong>
147
+ </li>
138
148
</ul>
139
149
</div>
140
150
</file>
@@ -209,8 +219,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
209
219
$$tlb : true ,
210
220
link : function ( $scope , $element , $attr , ctrl , $transclude ) {
211
221
var expression = $attr . ngRepeat ;
212
- var match = expression . match ( / ^ \s * ( [ \s \S ] + ?) \s + i n \s + ( [ \s \S ] + ?) (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ?) ) ? \s * $ / ) ,
213
- trackByExp , trackByExpGetter , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ,
222
+ var match = expression . match ( / ^ \s * ( [ \s \S ] + ?) \s + i n \s + ( [ \s \S ] + ?) (?: \s + a s \s + ( [ \s \S ] + ? ) ) ? (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ?) ) ? \s * $ / ) ,
223
+ trackByExp , trackByExpGetter , aliasAs , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ,
214
224
lhs , rhs , valueIdentifier , keyIdentifier ,
215
225
hashFnLocals = { $id : hashKey } ;
216
226
@@ -221,7 +231,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
221
231
222
232
lhs = match [ 1 ] ;
223
233
rhs = match [ 2 ] ;
224
- trackByExp = match [ 3 ] ;
234
+ aliasAs = match [ 3 ] ;
235
+ trackByExp = match [ 4 ] ;
225
236
226
237
if ( trackByExp ) {
227
238
trackByExpGetter = $parse ( trackByExp ) ;
@@ -273,6 +284,10 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
273
284
nextBlockOrder = [ ] ,
274
285
elementsToRemove ;
275
286
287
+ if ( aliasAs ) {
288
+ $scope [ aliasAs ] = collection ;
289
+ }
290
+
276
291
var updateScope = function ( scope , index ) {
277
292
scope [ valueIdentifier ] = value ;
278
293
if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
0 commit comments