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 {
334
334
` ,
335
335
} )
336
336
class BasicSelectOnPushPreselected {
337
+ @ViewChild ( SbbSelect ) select : SbbSelect ;
337
338
foods : any [ ] = [
338
339
{ value : 'steak-0' , viewValue : 'Steak' } ,
339
340
{ value : 'pizza-1' , viewValue : 'Pizza' } ,
@@ -3769,6 +3770,15 @@ describe('SbbSelect', () => {
3769
3770
3770
3771
expect ( select . textContent ) . not . toContain ( 'Pizza' ) ;
3771
3772
} ) ) ;
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
+ } ) ) ;
3772
3782
} ) ;
3773
3783
3774
3784
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
855
855
// Defer setting the value in order to avoid the "Expression
856
856
// has changed after it was checked" errors from Angular.
857
857
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 ) ;
859
863
this . stateChanges . next ( ) ;
860
864
} ) ;
861
865
}
You can’t perform that action at this time.
0 commit comments