摘要控制角度2

时间:2016-12-23 07:01:12

标签: angular ionic2

我在ts文件中尝试了 AbstractControl ,在构建应用时显示错误属性不存在{[key:string]:any} Abstractcontrol

ts文件: -

errors: ( {[ FormGroup     : string ] : void} )
getError(errorCode: string): any {
    return isPresent(this.control) ? this.control.getError(errorCode, this.path) : null;
}   

hasError(errorCode: string): boolean {
    return isPresent(this.getError(errorCode, this.path));
}
this.myForm =  new FormGroup({
        'firstname'      : new FormControl('',[Validators.required,Validators.minLength(3)]),
        'lastname'       : new FormControl('', [Validators.required,Validators.minLength(1)]),
        'useridphone'    : new FormControl('', Validators.required),
        'password'       : new FormControl('',Validators.compose([Validators.required,Validators.minLength(4),
                           Validators.pattern(this.passwordRegex)])),
        'confirmpassword': new FormControl('',Validators.required),
        'email'          : new FormControl( '', Validators.compose([ Validators.required, Validators.pattern(this.emailRegex) ]) )
  }

如何为这些字段编写abstractcontrol .....

1 个答案:

答案 0 :(得分:0)

export class FormGroup extends AbstractControl {
  constructor(
      public controls: {[key: string]: AbstractControl},
      validator: ValidatorFn = null,
      asyncValidator: AsyncValidatorFn = null
    ) {
    super(validator, asyncValidator);
    this._initObservables();
    this._setUpControls();
    this.updateValueAndValidity({onlySelf: true, emitEvent: false});
  }
  //...
}

您可以查看https://toddmotto.com/reactive-formgroup-validation-angular-2

相关问题