File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -3175,6 +3175,16 @@ describe('MatSelect', () => {
3175
3175
3176
3176
expect ( trigger . textContent ) . not . toContain ( 'Pizza' ) ;
3177
3177
} ) ) ;
3178
+
3179
+ it ( 'should sync up the form control value with the component value' , fakeAsync ( ( ) => {
3180
+ const fixture = TestBed . createComponent ( BasicSelectOnPushPreselected ) ;
3181
+ fixture . detectChanges ( ) ;
3182
+ flush ( ) ;
3183
+
3184
+ expect ( fixture . componentInstance . control . value ) . toBe ( 'pizza-1' ) ;
3185
+ expect ( fixture . componentInstance . select . value ) . toBe ( 'pizza-1' ) ;
3186
+ } ) ) ;
3187
+
3178
3188
} ) ;
3179
3189
3180
3190
describe ( 'with custom trigger' , ( ) => {
@@ -5426,6 +5436,7 @@ class BasicSelectOnPush {
5426
5436
` ,
5427
5437
} )
5428
5438
class BasicSelectOnPushPreselected {
5439
+ @ViewChild ( MatSelect ) select : MatSelect ;
5429
5440
foods : any [ ] = [
5430
5441
{ value : 'steak-0' , viewValue : 'Steak' } ,
5431
5442
{ value : 'pizza-1' , viewValue : 'Pizza' } ,
Original file line number Diff line number Diff line change @@ -831,7 +831,11 @@ export abstract class _MatSelectBase<C>
831
831
// Defer setting the value in order to avoid the "Expression
832
832
// has changed after it was checked" errors from Angular.
833
833
Promise . resolve ( ) . then ( ( ) => {
834
- this . _setSelectionByValue ( this . ngControl ? this . ngControl . value : this . _value ) ;
834
+ if ( this . ngControl ) {
835
+ this . _value = this . ngControl . value ;
836
+ }
837
+
838
+ this . _setSelectionByValue ( this . _value ) ;
835
839
this . stateChanges . next ( ) ;
836
840
} ) ;
837
841
}
You can’t perform that action at this time.
0 commit comments