Skip to content

Commit 5b597de

Browse files
committed
fix(forms): default the initial value of Control to null
1 parent 4d28167 commit 5b597de

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

modules/angular2/src/forms/directives/ng_form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class NgForm extends ControlContainer implements Form {
7474
addControl(dir: NgControl): void {
7575
this._later(_ => {
7676
var container = this._findContainer(dir.path);
77-
var c = new Control("");
77+
var c = new Control();
7878
setUpControl(c, dir);
7979
container.addControl(dir.name, c);
8080
c.updateValidity();

modules/angular2/src/forms/directives/ng_model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
3636
exportAs: 'form'
3737
})
3838
export class NgModel extends NgControl {
39-
_control = new Control("");
39+
_control = new Control();
4040
_added = false;
4141
update = new EventEmitter();
4242
model: any;

modules/angular2/src/forms/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class AbstractControl {
144144
export class Control extends AbstractControl {
145145
_onChange: Function;
146146

147-
constructor(value: any, validator: Function = Validators.nullValidator) {
147+
constructor(value: any = null, validator: Function = Validators.nullValidator) {
148148
super(validator);
149149
this._value = value;
150150
this.updateValidity({onlySelf: true});

modules/angular2/test/forms/model_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import {ObservableWrapper} from 'angular2/src/facade/async';
1919
export function main() {
2020
describe("Form Model", () => {
2121
describe("Control", () => {
22+
it("should default the value to null", () => {
23+
var c = new Control();
24+
expect(c.value).toBe(null);
25+
expect(c.validator).toBe(Validators.nullValidator);
26+
});
27+
2228
describe("validator", () => {
2329
it("should run validator with the initial value", () => {
2430
var c = new Control("value", Validators.required);

0 commit comments

Comments
 (0)