@@ -22,6 +22,7 @@ import {
22
22
forwardRef ,
23
23
Inject ,
24
24
Input ,
25
+ OnChanges ,
25
26
OnDestroy ,
26
27
OnInit ,
27
28
Output ,
@@ -96,6 +97,7 @@ export class MatListOption extends _MatListOptionMixinBase
96
97
97
98
private _selected = false ;
98
99
private _disabled = false ;
100
+ private _parentStateSubscription : Subscription ;
99
101
100
102
/** Whether the option has focus. */
101
103
_hasFocus : boolean = false ;
@@ -140,6 +142,9 @@ export class MatListOption extends _MatListOptionMixinBase
140
142
/** @docs -private */
141
143
@Inject ( forwardRef ( ( ) => MatSelectionList ) ) public selectionList : MatSelectionList ) {
142
144
super ( ) ;
145
+
146
+ this . _parentStateSubscription = this . selectionList . _stateChanges
147
+ . subscribe ( ( ) => this . _changeDetector . markForCheck ( ) ) ;
143
148
}
144
149
145
150
ngOnInit ( ) {
@@ -172,6 +177,7 @@ export class MatListOption extends _MatListOptionMixinBase
172
177
}
173
178
174
179
this . selectionList . _removeOptionFromList ( this ) ;
180
+ this . _parentStateSubscription . unsubscribe ( ) ;
175
181
}
176
182
177
183
/** Toggles the selection state of the option. */
@@ -265,11 +271,14 @@ export class MatListOption extends _MatListOptionMixinBase
265
271
changeDetection : ChangeDetectionStrategy . OnPush
266
272
} )
267
273
export class MatSelectionList extends _MatSelectionListMixinBase implements FocusableOption ,
268
- CanDisable , CanDisableRipple , AfterContentInit , ControlValueAccessor , OnDestroy {
274
+ CanDisable , CanDisableRipple , AfterContentInit , ControlValueAccessor , OnDestroy , OnChanges {
269
275
270
276
/** The FocusKeyManager which handles focus. */
271
277
_keyManager : FocusKeyManager < MatListOption > ;
272
278
279
+ /** Used to notify any child components listening to state changes. */
280
+ readonly _stateChanges = new EventEmitter < void > ( ) ;
281
+
273
282
/** The option components contained within this selection-list. */
274
283
@ContentChildren ( MatListOption ) options : QueryList < MatListOption > ;
275
284
@@ -296,6 +305,7 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
296
305
/** Used for storing the values that were assigned before the options were initialized. */
297
306
private _tempValues : string [ ] | null ;
298
307
308
+ /** Subscription to sync value changes in the SelectionModel back to the SelectionList. */
299
309
private _modelChanges = Subscription . EMPTY ;
300
310
301
311
/** View to model callback that should be called if the list or its options lost focus. */
@@ -335,6 +345,10 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
335
345
} ) ;
336
346
}
337
347
348
+ ngOnChanges ( ) {
349
+ this . _stateChanges . next ( ) ;
350
+ }
351
+
338
352
ngOnDestroy ( ) {
339
353
this . _modelChanges . unsubscribe ( ) ;
340
354
}
0 commit comments