@@ -2317,31 +2317,33 @@ describe('select', function() {
2317
2317
} ) ;
2318
2318
2319
2319
it ( 'should keep the ngModel value when the selected option is recreated by ngRepeat' , function ( ) {
2320
-
2321
- scope . options = [ 'A' , 'B' , 'C' ] ;
2320
+ scope . options = [ { name : 'A' } , { name : 'B' } , { name : 'C' } ] ;
2322
2321
scope . obj = {
2323
2322
value : 'B'
2324
2323
} ;
2325
2324
2326
2325
compile (
2327
2326
'<select ng-model="obj.value">' +
2328
- '<option ng-repeat="option in options" value="{{option}}">{{option}}</option>' +
2327
+ '<option ng-repeat="option in options" value="{{option.name }}">{{option.name }}</option>' +
2329
2328
'</select>'
2330
2329
) ;
2331
2330
2332
2331
var optionElements = element . find ( 'option' ) ;
2333
2332
expect ( optionElements . length ) . toEqual ( 3 ) ;
2334
2333
expect ( optionElements [ 0 ] . value ) . toBe ( 'A' ) ;
2335
2334
expect ( optionElements [ 1 ] ) . toBeMarkedAsSelected ( ) ;
2335
+ expect ( scope . obj . value ) . toBe ( 'B' ) ;
2336
2336
2337
2337
scope . $apply ( function ( ) {
2338
- scope . options = [ 'B' , 'C' , 'D' ] ;
2338
+ // Only when new objects are used, ngRepeat re-creates the element from scratch
2339
+ scope . options = [ { name : 'B' } , { name : 'C' } , { name : 'D' } ] ;
2339
2340
} ) ;
2340
2341
2341
2342
optionElements = element . find ( 'option' ) ;
2342
2343
expect ( optionElements . length ) . toEqual ( 3 ) ;
2343
2344
expect ( optionElements [ 0 ] . value ) . toBe ( 'B' ) ;
2344
2345
expect ( optionElements [ 0 ] ) . toBeMarkedAsSelected ( ) ;
2346
+ expect ( scope . obj . value ) . toBe ( 'B' ) ;
2345
2347
} ) ;
2346
2348
2347
2349
} ) ;
0 commit comments