File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1380,7 +1380,7 @@ describe('MatChipList', () => {
1380
1380
} ) ;
1381
1381
} ) ;
1382
1382
1383
- it ( 'should preselected chip as selected inside an OnPush component' , fakeAsync ( ( ) => {
1383
+ it ( 'should preselect chip as selected inside an OnPush component' , fakeAsync ( ( ) => {
1384
1384
fixture = createComponent ( PreselectedChipInsideOnPush ) ;
1385
1385
fixture . detectChanges ( ) ;
1386
1386
tick ( ) ;
@@ -1390,6 +1390,21 @@ describe('MatChipList', () => {
1390
1390
. withContext ( 'Expected first chip to be selected.' ) . toContain ( 'mat-chip-selected' ) ;
1391
1391
} ) ) ;
1392
1392
1393
+ it ( 'should not throw when accessing the selected value too early in single selection mode' ,
1394
+ fakeAsync ( ( ) => {
1395
+ fixture = createComponent ( StandardChipList ) ;
1396
+ const chipList = fixture . debugElement . query ( By . directive ( MatChipList ) ) . componentInstance ;
1397
+ expect ( ( ) => chipList . selected ) . not . toThrow ( ) ;
1398
+ } ) ) ;
1399
+
1400
+ it ( 'should not throw when accessing the selected value too early in multi selection mode' ,
1401
+ fakeAsync ( ( ) => {
1402
+ fixture = createComponent ( StandardChipList ) ;
1403
+ const chipList = fixture . debugElement . query ( By . directive ( MatChipList ) ) . componentInstance ;
1404
+ chipList . multiple = true ;
1405
+ expect ( ( ) => chipList . selected ) . not . toThrow ( ) ;
1406
+ } ) ) ;
1407
+
1393
1408
function createComponent < T > ( component : Type < T > , providers : Provider [ ] = [ ] , animationsModule :
1394
1409
Type < NoopAnimationsModule > | Type < BrowserAnimationsModule > = NoopAnimationsModule ) :
1395
1410
ComponentFixture < T > {
Original file line number Diff line number Diff line change @@ -154,7 +154,8 @@ export class MatChipList extends _MatChipListBase implements MatFormFieldControl
154
154
155
155
/** The array of selected chips inside chip list. */
156
156
get selected ( ) : MatChip [ ] | MatChip {
157
- return this . multiple ? this . _selectionModel . selected : this . _selectionModel . selected [ 0 ] ;
157
+ return this . multiple ? ( this . _selectionModel ?. selected || [ ] ) :
158
+ this . _selectionModel ?. selected [ 0 ] ;
158
159
}
159
160
160
161
/** The ARIA role applied to the chip list. */
You can’t perform that action at this time.
0 commit comments