電子メールが有効ではないが、htmlに表示されていないときに、md-hintを表示しようとしています。Data-Drivenフォームで電子メールバリデータを使用してmd-hintを表示しない
HTML
<form [formGroup]="myForm" (ngSubmit)="onSignup()">
<md-input-container class="col-md-6 md-icon-left">
<md-icon class="material-icons">mail_outline</md-icon>
<input formControlName="email" mdInput #email type="email" name="email" class="form-control" placeholder="Email">
<md-hint *ngIf="!email.pristine && email.errors != null && email.errors['noEmail']">Invalid mail address</md-hint>
</md-input-container>
</form>
component.ts
myForm: FormGroup;
error = false;
errorMessage = '';
constructor(private fb: FormBuilder,
private authService: AuthService,
rv: RutValidator) {
this.myForm = this.fb.group({
email: ['', Validators.compose([
Validators.required,
this.isEmail
])],
});
}
isEmail(control: FormControl): {[s: string]: boolean} {
if (!control.value.match(/^\[email protected][a-zA-Z_]+?\.[a-zA-Z]{2,3}$/)) {
return {noEmail: true};
}
}
あなたの助けを
ありがとう!
を 'テンプレート内email'変数は' HTMLInputElement'インスタンスです。 FormControlインスタンスを使用して 'myForm.get( 'email')' – yurzui