@@ -423,13 +423,10 @@ export abstract class _MatSelectBase<C>
423
423
return this . _value ;
424
424
}
425
425
set value ( newValue : any ) {
426
- // Always re-assign an array, because it might have been mutated.
427
- if ( newValue !== this . _value || ( this . _multiple && Array . isArray ( newValue ) ) ) {
428
- if ( this . options ) {
429
- this . _setSelectionByValue ( newValue ) ;
430
- }
426
+ const hasAssigned = this . _assignValue ( newValue ) ;
431
427
432
- this . _value = newValue ;
428
+ if ( hasAssigned ) {
429
+ this . _onChange ( newValue ) ;
433
430
}
434
431
}
435
432
private _value : any ;
@@ -661,7 +658,7 @@ export abstract class _MatSelectBase<C>
661
658
* @param value New value to be written to the model.
662
659
*/
663
660
writeValue ( value : any ) : void {
664
- this . value = value ;
661
+ this . _assignValue ( value ) ;
665
662
}
666
663
667
664
/**
@@ -886,10 +883,10 @@ export abstract class _MatSelectBase<C>
886
883
throw getMatSelectNonArrayValueError ( ) ;
887
884
}
888
885
889
- value . forEach ( ( currentValue : any ) => this . _selectValue ( currentValue ) ) ;
886
+ value . forEach ( ( currentValue : any ) => this . _selectOptionByValue ( currentValue ) ) ;
890
887
this . _sortValues ( ) ;
891
888
} else {
892
- const correspondingOption = this . _selectValue ( value ) ;
889
+ const correspondingOption = this . _selectOptionByValue ( value ) ;
893
890
894
891
// Shift focus to the active item. Note that we shouldn't do this in multiple
895
892
// mode, because we don't know what option the user interacted with last.
@@ -909,7 +906,7 @@ export abstract class _MatSelectBase<C>
909
906
* Finds and selects and option based on its value.
910
907
* @returns Option that has the corresponding value.
911
908
*/
912
- private _selectValue ( value : any ) : MatOption | undefined {
909
+ private _selectOptionByValue ( value : any ) : MatOption | undefined {
913
910
const correspondingOption = this . options . find ( ( option : MatOption ) => {
914
911
// Skip options that are already in the model. This allows us to handle cases
915
912
// where the same primitive value is selected multiple times.
@@ -936,6 +933,20 @@ export abstract class _MatSelectBase<C>
936
933
return correspondingOption ;
937
934
}
938
935
936
+ /** Assigns a specific value to the select. Returns whether the value has changed. */
937
+ private _assignValue ( newValue : any | any [ ] ) : boolean {
938
+ // Always re-assign an array, because it might have been mutated.
939
+ if ( newValue !== this . _value || ( this . _multiple && Array . isArray ( newValue ) ) ) {
940
+ if ( this . options ) {
941
+ this . _setSelectionByValue ( newValue ) ;
942
+ }
943
+
944
+ this . _value = newValue ;
945
+ return true ;
946
+ }
947
+ return false ;
948
+ }
949
+
939
950
/** Sets up a key manager to listen to keyboard events on the overlay panel. */
940
951
private _initKeyManager ( ) {
941
952
this . _keyManager = new ActiveDescendantKeyManager < MatOption > ( this . options )
0 commit comments