@@ -411,13 +411,10 @@ export abstract class _MatSelectBase<C>
411
411
return this . _value ;
412
412
}
413
413
set value ( newValue : any ) {
414
- // Always re-assign an array, because it might have been mutated.
415
- if ( newValue !== this . _value || ( this . _multiple && Array . isArray ( newValue ) ) ) {
416
- if ( this . options ) {
417
- this . _setSelectionByValue ( newValue ) ;
418
- }
414
+ const hasAssigned = this . _assignValue ( newValue ) ;
419
415
420
- this . _value = newValue ;
416
+ if ( hasAssigned ) {
417
+ this . _onChange ( newValue ) ;
421
418
}
422
419
}
423
420
private _value : any ;
@@ -649,7 +646,7 @@ export abstract class _MatSelectBase<C>
649
646
* @param value New value to be written to the model.
650
647
*/
651
648
writeValue ( value : any ) : void {
652
- this . value = value ;
649
+ this . _assignValue ( value ) ;
653
650
}
654
651
655
652
/**
@@ -874,10 +871,10 @@ export abstract class _MatSelectBase<C>
874
871
throw getMatSelectNonArrayValueError ( ) ;
875
872
}
876
873
877
- value . forEach ( ( currentValue : any ) => this . _selectValue ( currentValue ) ) ;
874
+ value . forEach ( ( currentValue : any ) => this . _selectOptionByValue ( currentValue ) ) ;
878
875
this . _sortValues ( ) ;
879
876
} else {
880
- const correspondingOption = this . _selectValue ( value ) ;
877
+ const correspondingOption = this . _selectOptionByValue ( value ) ;
881
878
882
879
// Shift focus to the active item. Note that we shouldn't do this in multiple
883
880
// mode, because we don't know what option the user interacted with last.
@@ -897,7 +894,7 @@ export abstract class _MatSelectBase<C>
897
894
* Finds and selects and option based on its value.
898
895
* @returns Option that has the corresponding value.
899
896
*/
900
- private _selectValue ( value : any ) : MatOption | undefined {
897
+ private _selectOptionByValue ( value : any ) : MatOption | undefined {
901
898
const correspondingOption = this . options . find ( ( option : MatOption ) => {
902
899
// Skip options that are already in the model. This allows us to handle cases
903
900
// where the same primitive value is selected multiple times.
@@ -924,6 +921,20 @@ export abstract class _MatSelectBase<C>
924
921
return correspondingOption ;
925
922
}
926
923
924
+ /** Assigns a specific value to the select. Returns whether the value has changed. */
925
+ private _assignValue ( newValue : any | any [ ] ) : boolean {
926
+ // Always re-assign an array, because it might have been mutated.
927
+ if ( newValue !== this . _value || ( this . _multiple && Array . isArray ( newValue ) ) ) {
928
+ if ( this . options ) {
929
+ this . _setSelectionByValue ( newValue ) ;
930
+ }
931
+
932
+ this . _value = newValue ;
933
+ return true ;
934
+ }
935
+ return false ;
936
+ }
937
+
927
938
/** Sets up a key manager to listen to keyboard events on the overlay panel. */
928
939
private _initKeyManager ( ) {
929
940
this . _keyManager = new ActiveDescendantKeyManager < MatOption > ( this . options )
0 commit comments