diff --git a/modules/angular2/src/forms/directives/ng_form.ts b/modules/angular2/src/forms/directives/ng_form.ts index 1527fad57b..33a4bd8f26 100644 --- a/modules/angular2/src/forms/directives/ng_form.ts +++ b/modules/angular2/src/forms/directives/ng_form.ts @@ -74,7 +74,7 @@ export class NgForm extends ControlContainer implements Form { addControl(dir: NgControl): void { this._later(_ => { var container = this._findContainer(dir.path); - var c = new Control(""); + var c = new Control(); setUpControl(c, dir); container.addControl(dir.name, c); c.updateValidity(); diff --git a/modules/angular2/src/forms/directives/ng_model.ts b/modules/angular2/src/forms/directives/ng_model.ts index 9e05aa7cbe..7ee53645f3 100644 --- a/modules/angular2/src/forms/directives/ng_model.ts +++ b/modules/angular2/src/forms/directives/ng_model.ts @@ -36,7 +36,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe exportAs: 'form' }) export class NgModel extends NgControl { - _control = new Control(""); + _control = new Control(); _added = false; update = new EventEmitter(); model: any; diff --git a/modules/angular2/src/forms/model.ts b/modules/angular2/src/forms/model.ts index 15d11dc192..9adf182574 100644 --- a/modules/angular2/src/forms/model.ts +++ b/modules/angular2/src/forms/model.ts @@ -144,7 +144,7 @@ export class AbstractControl { export class Control extends AbstractControl { _onChange: Function; - constructor(value: any, validator: Function = Validators.nullValidator) { + constructor(value: any = null, validator: Function = Validators.nullValidator) { super(validator); this._value = value; this.updateValidity({onlySelf: true}); diff --git a/modules/angular2/test/forms/model_spec.ts b/modules/angular2/test/forms/model_spec.ts index a1b543af1a..c0ecc74048 100644 --- a/modules/angular2/test/forms/model_spec.ts +++ b/modules/angular2/test/forms/model_spec.ts @@ -19,6 +19,12 @@ import {ObservableWrapper} from 'angular2/src/facade/async'; export function main() { describe("Form Model", () => { describe("Control", () => { + it("should default the value to null", () => { + var c = new Control(); + expect(c.value).toBe(null); + expect(c.validator).toBe(Validators.nullValidator); + }); + describe("validator", () => { it("should run validator with the initial value", () => { var c = new Control("value", Validators.required);