下面是我的组件文件(login.component.html)
<form >
<div id="login-container" [class.mat-elevation-z12]="!isActive"
[class.mat-elevation-z8]="isActive">
<h2>Login</h2>
<mat-form-field class="example-full-width">
<input matInput placeholder="Email address"
[formControl]="emailFormControl" required>
<mat-error *ngIf="emailFormControl.hasError('required')">
Please enter email id
</mat-error>
</mat-form-field>
<mat-form-field >
<input matInput placeholder="Password" minlength="6"
maxlength="15" [type]="hide ? 'password' : 'text'"
[formControl]="passFormControl" required>
<mat-error *ngIf="passFormControl.hasError('required')">
Please enter password
</mat-error>
<mat-error *ngIf="!minlength">
Password must be 6-15 characters long
</mat-error>
</mat-form-field>
<mat-slide-toggle color="primary"><span class="toggle-btn">Remember
me</span></mat-slide-toggle>
<div>
<a [routerLink]="['../signup']"><button mat-raised-button
class="Sign-Up-btn">Sign Up</button></a>
<a [routerLink]="['../']"><button mat-raised-button color="primary"
class="Login-btn" >Login</button></a>
</div>
<div class="footer-sec">
<br><br>
<a [routerLink]="['../forgot-pass']">Forgot Password?</a><br><br>
<mat-divider></mat-divider>
<p>Powered by yletlabs pvt ltd</p>
</div>
</div>
<form >
(login.component.ts)文件
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroupDirective, NgForm, Validators} from
'@angular/forms';
import {ErrorStateMatcher} from '@angular/material/core';
@Component({
selector: 'ylb-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
emailFormControl = new FormControl('', [
Validators.required,
]);
passFormControl = new FormControl('', [
Validators.required,
]);
hide =true;//password hiding
}
输入和密码组件都正常工作并使用显示正确的错误消息
<mat-error>,
现在,如果我点击登录/注册所需的错误消息必须进入
<mat-error>.
我怎样才能实现这一目标?阅读许多文章完全混淆 .
1 回答
看看下面的代码
login.component.html
login.component.ts
validator.util.ts