@@ -650,6 +650,22 @@ describe('MatSelectionList with forms', () => {
650
650
expect ( ngModel . pristine )
651
651
. toBe ( false , 'Expected the selection-list to be dirty after state change.' ) ;
652
652
} ) ) ;
653
+
654
+ it ( 'should remove a selected option from the value on destroy' , fakeAsync ( ( ) => {
655
+ listOptions [ 1 ] . selected = true ;
656
+ listOptions [ 2 ] . selected = true ;
657
+
658
+ fixture . detectChanges ( ) ;
659
+
660
+ expect ( fixture . componentInstance . selectedOptions ) . toEqual ( [ 'opt2' , 'opt3' ] ) ;
661
+
662
+ fixture . componentInstance . renderLastOption = false ;
663
+ fixture . detectChanges ( ) ;
664
+ tick ( ) ;
665
+
666
+ expect ( fixture . componentInstance . selectedOptions ) . toEqual ( [ 'opt2' ] ) ;
667
+ } ) ) ;
668
+
653
669
} ) ;
654
670
655
671
describe ( 'and formControl' , ( ) => {
@@ -768,7 +784,7 @@ class SelectionListWithDisabledOption {
768
784
769
785
@Component ( { template : `
770
786
<mat-selection-list>
771
- <mat-list-option [selected]="true">Item</mat-list-option>
787
+ <mat-list-option [selected]="true" value="item" >Item</mat-list-option>
772
788
</mat-selection-list>` } )
773
789
class SelectionListWithSelectedOption {
774
790
}
@@ -800,11 +816,12 @@ class SelectionListWithTabindexBinding {
800
816
<mat-selection-list [(ngModel)]="selectedOptions">
801
817
<mat-list-option value="opt1">Option 1</mat-list-option>
802
818
<mat-list-option value="opt2">Option 2</mat-list-option>
803
- <mat-list-option value="opt3">Option 3</mat-list-option>
819
+ <mat-list-option value="opt3" *ngIf="renderLastOption" >Option 3</mat-list-option>
804
820
</mat-selection-list>`
805
821
} )
806
822
class SelectionListWithModel {
807
823
selectedOptions : string [ ] = [ ] ;
824
+ renderLastOption = true ;
808
825
}
809
826
810
827
@Component ( {
0 commit comments