diff --git a/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts b/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts index 308e021d29..afc5c85797 100644 --- a/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts +++ b/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts @@ -113,9 +113,8 @@ export class NgSelectOption implements OnDestroy { @Input('value') set value(value: any) { - if (this._select == null) return; this._setElementValue(value); - this._select.writeValue(this._select.value); + if (isPresent(this._select)) this._select.writeValue(this._select.value); } /** @internal */ diff --git a/modules/angular2/test/common/forms/integration_spec.ts b/modules/angular2/test/common/forms/integration_spec.ts index e37195a696..951a32f6d9 100644 --- a/modules/angular2/test/common/forms/integration_spec.ts +++ b/modules/angular2/test/common/forms/integration_spec.ts @@ -378,6 +378,30 @@ export function main() { }); })); + it("with basic selection and value bindings", + inject([TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async) => { + var t = ``; + + tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => { + var testComp = fixture.debugElement.componentInstance; + testComp.list = [{"id": "0", "name": "SF"}, {"id": "1", "name": "NYC"}]; + fixture.detectChanges(); + + var sfOption = fixture.debugElement.query(By.css("option")); + expect(sfOption.nativeElement.value).toEqual('0'); + + testComp.list[0]['id'] = '2'; + fixture.detectChanges(); + expect(sfOption.nativeElement.value).toEqual('2'); + async.done(); + }); + })); + it("with ngControl", inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {