@@ -24,6 +24,8 @@ import {ControlValueAccessor, NgControl} from '@angular/forms';
2424import { coerceBooleanProperty } from '../core/coercion/boolean-property' ;
2525import { ConnectedOverlayDirective } from '../core/overlay/overlay-directives' ;
2626import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
27+ import 'rxjs/add/operator/startWith' ;
28+
2729
2830/**
2931 * The following style constants are necessary to save here in order
@@ -123,9 +125,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
123125 /** The placeholder displayed in the trigger of the select. */
124126 private _placeholder : string ;
125127
126- /** Holds a value that was attempted to be assigned before the component was initialized. */
127- private _tempValue : any ;
128-
129128 /** The animation state of the placeholder. */
130129 _placeholderState = '' ;
131130
@@ -246,15 +245,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
246245 this . _initKeyManager ( ) ;
247246 this . _resetOptions ( ) ;
248247
249- // Assign any values that were deferred until the component is initialized.
250- if ( this . _tempValue ) {
251- Promise . resolve ( null ) . then ( ( ) => {
252- this . writeValue ( this . _tempValue ) ;
253- this . _tempValue = null ;
254- } ) ;
255- }
256-
257- this . _changeSubscription = this . options . changes . subscribe ( ( ) => {
248+ this . _changeSubscription = this . options . changes . startWith ( null ) . subscribe ( ( ) => {
258249 this . _resetOptions ( ) ;
259250
260251 if ( this . _control ) {
@@ -267,8 +258,14 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
267258
268259 ngOnDestroy ( ) {
269260 this . _dropSubscriptions ( ) ;
270- this . _changeSubscription . unsubscribe ( ) ;
271- this . _tabSubscription . unsubscribe ( ) ;
261+
262+ if ( this . _changeSubscription ) {
263+ this . _changeSubscription . unsubscribe ( ) ;
264+ }
265+
266+ if ( this . _tabSubscription ) {
267+ this . _tabSubscription . unsubscribe ( ) ;
268+ }
272269 }
273270
274271 /** Toggles the overlay panel open or closed. */
@@ -304,11 +301,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
304301 writeValue ( value : any ) : void {
305302 if ( this . options ) {
306303 this . _setSelectionByValue ( value ) ;
307- } else {
308- // In reactive forms, writeValue() will be called synchronously before
309- // the select's child options have been created. We save the value and
310- // assign it after everything is set up, in order to avoid lost data.
311- this . _tempValue = value ;
312304 }
313305 }
314306
0 commit comments