Angular2密码比较错误为无法读取未定义的属性“密码”

时间:2017-06-12 08:08:42

标签: angular angular2-forms

我正在尝试比较密码,因此将错误视为

  

无法读取未定义的属性“密码”

这是我的代码:

    import { NgForm, FormGroup,FormControl,Validators,FormBuilder} from "@angular/forms"
        export class Customer {
            Email: string = "";
            Password: string = "";
            Conf_Password: string = "";
            xyz: FormGroup = null;
            constructor() {
                var _builder = new FormBuilder();
                this.xyz = _builder.group({      
                    'Password': ['', Validators.required],
'Conf_Password': ['', Validators.required,this.validatePasswordConfirmation],

validatePasswordConfirmation(): any {
    let valid = true;
    if (this.Password != this.Conf_Password) {
        valid = false;
        debugger;
    }
    return valid;
}

这是我的HTML代码

<form [formGroup]="custobj.xyz">
 <b>Password</b><input type="text" id="txt1" formControlName="Password"
                           [(ngModel)]="custobj.Password" /><br />
 <b>ComparePassword</b><input type="text" id="txt1" formControlName="Conf_Password"
                           [(ngModel)]="custobj.Conf_Password" /><br /> 
 <b>Password</b><input type="text" id="txt1" formControlName="Password"
                           [(ngModel)]="custobj.Password" /><br />
 <b>ComparePassword</b><input type="text" id="txt1" formControlName="Conf_Password"
                           [(ngModel)]="custobj.Conf_Password" /><br />

0 个答案:

没有答案