fix(select): set value individually from ngModel

Closes #7975

Closes #7978
This commit is contained in:
Kara Erickson 2016-04-08 12:00:04 -07:00 committed by Kara
parent f371c9066d
commit e1e44a910e
2 changed files with 25 additions and 2 deletions

View File

@ -113,9 +113,8 @@ export class NgSelectOption implements OnDestroy {
@Input('value') @Input('value')
set value(value: any) { set value(value: any) {
if (this._select == null) return;
this._setElementValue(value); this._setElementValue(value);
this._select.writeValue(this._select.value); if (isPresent(this._select)) this._select.writeValue(this._select.value);
} }
/** @internal */ /** @internal */

View File

@ -378,6 +378,30 @@ export function main() {
}); });
})); }));
it("with basic selection and value bindings",
inject([TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async) => {
var t = `<select>
<option *ngFor="#city of list" [value]="city['id']">
{{ city['name'] }}
</option>
</select>`;
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", it("with ngControl",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
async) => { async) => {