112
112
* For example: `item in items | filter:searchText track by item.id` is a pattern that might be used to apply a filter
113
113
* to items in conjunction with a tracking expression.
114
114
*
115
+ * * `variable in expression as alias_expression` – You can also provide an optional alias expression which will then store the
116
+ * intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message
117
+ * when a filter is active on the repeater, but the filtered result set is empty.
118
+ *
119
+ * For example: `item in items | filter:x as results` will store the fragment of the repeated items as `results`, but only after
120
+ * the items have been processed through the filter.
121
+ *
115
122
* @example
116
123
* This example initializes the scope to a list of names and
117
124
* then uses `ngRepeat` to display every person:
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>
@@ -208,8 +218,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
208
218
$$tlb : true ,
209
219
link : function ( $scope , $element , $attr , ctrl , $transclude ) {
210
220
var expression = $attr . ngRepeat ;
211
- 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 * $ / ) ,
212
- trackByExp , trackByExpGetter , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ,
221
+ 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 + a s \s + ( [ \s \S ] + ? ) ) ? \s * $ / ) ,
222
+ trackByExp , trackByExpGetter , aliasAs , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ,
213
223
lhs , rhs , valueIdentifier , keyIdentifier ,
214
224
hashFnLocals = { $id : hashKey } ;
215
225
@@ -221,6 +231,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
221
231
lhs = match [ 1 ] ;
222
232
rhs = match [ 2 ] ;
223
233
trackByExp = match [ 3 ] ;
234
+ aliasAs = match [ 4 ] ;
224
235
225
236
if ( trackByExp ) {
226
237
trackByExpGetter = $parse ( trackByExp ) ;
@@ -272,6 +283,10 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
272
283
nextBlockOrder = [ ] ,
273
284
elementsToRemove ;
274
285
286
+ if ( aliasAs ) {
287
+ $scope [ aliasAs ] = collection ;
288
+ }
289
+
275
290
var updateScope = function ( scope , index ) {
276
291
scope [ valueIdentifier ] = value ;
277
292
if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
0 commit comments