fix(forms): default the initial value of Control to null
This commit is contained in:
parent
4d28167bc0
commit
5b597de18c
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue