File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
src/angular/select/select Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,7 @@ class BasicSelectOnPush {
334334 ` ,
335335} )
336336class BasicSelectOnPushPreselected {
337+ @ViewChild ( SbbSelect ) select : SbbSelect ;
337338 foods : any [ ] = [
338339 { value : 'steak-0' , viewValue : 'Steak' } ,
339340 { value : 'pizza-1' , viewValue : 'Pizza' } ,
@@ -3769,6 +3770,15 @@ describe('SbbSelect', () => {
37693770
37703771 expect ( select . textContent ) . not . toContain ( 'Pizza' ) ;
37713772 } ) ) ;
3773+
3774+ it ( 'should sync up the form control value with the component value' , fakeAsync ( ( ) => {
3775+ const fixture = TestBed . createComponent ( BasicSelectOnPushPreselected ) ;
3776+ fixture . detectChanges ( ) ;
3777+ flush ( ) ;
3778+
3779+ expect ( fixture . componentInstance . control . value ) . toBe ( 'pizza-1' ) ;
3780+ expect ( fixture . componentInstance . select . value ) . toBe ( 'pizza-1' ) ;
3781+ } ) ) ;
37723782 } ) ;
37733783
37743784 describe ( 'when resetting the value by setting null or undefined' , ( ) => {
Original file line number Diff line number Diff line change @@ -855,7 +855,11 @@ export class SbbSelect
855855 // Defer setting the value in order to avoid the "Expression
856856 // has changed after it was checked" errors from Angular.
857857 Promise . resolve ( ) . then ( ( ) => {
858- this . _setSelectionByValue ( this . ngControl ? this . ngControl . value : this . _value ) ;
858+ if ( this . ngControl ) {
859+ this . _value = this . ngControl . value ;
860+ }
861+
862+ this . _setSelectionByValue ( this . _value ) ;
859863 this . stateChanges . next ( ) ;
860864 } ) ;
861865 }
You can’t perform that action at this time.
0 commit comments