您在需要流的地方提供了无效的对象。您可以提供 Observable、Promise ReadableStream、Array、AsyncIterable 或 Iterable
[email  prected] “将RXJS从7.4.0更改为6.4.0不能解决问题,
这是TS文件
get errorMessageForPassword(): string {
const form: FormControl = (this.thirdFormGroup.get('passWord') as FormControl);
return form.hasError('required') ?
'Password is required' :
form.hasError('minlength') ?
'Password must be at least 6 characters' : '';
}
,这是HTML文件
<div class="col-md form-group">
<mat-form-field appearance="standard">
<mat-label>Password</mat-label>
<input matInput [type]="hide ? 'password' : 'text'" placeholder="**"
formControlName="passWord" [(ngModel)]="testUser.passWord" id="passWord"
name="passWord" >
<button mat-icon-button matSuffix (click)="hide = !hide">
<mat-icon>{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
<mat-error>{{ errorMessageForPassword }}</mat-error>
</mat-form-field>
</div>
Using the command "npm i [email protected]" to change the rxjs from 7.4.0 to 6.4.0 does not the solve the problem
This is the ts file
get errorMessageForPassword(): string {
const form: FormControl = (this.thirdFormGroup.get('passWord') as FormControl);
return form.hasError('required') ?
'Password is required' :
form.hasError('minlength') ?
'Password must be at least 6 characters' : '';
}
This the html file
<div class="col-md form-group">
<mat-form-field appearance="standard">
<mat-label>Password</mat-label>
<input matInput [type]="hide ? 'password' : 'text'" placeholder="**"
formControlName="passWord" [(ngModel)]="testUser.passWord" id="passWord"
name="passWord" >
<button mat-icon-button matSuffix (click)="hide = !hide">
<mat-icon>{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
<mat-error>{{ errorMessageForPassword }}</mat-error>
</mat-form-field>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我解决了这个问题。问题是我如何在 formGroup 验证器函数中处理密码的属性声明。
第一个代码片段是我在使用formbuilder时处理错误格式的验证器的方式。
第二个代码片段是使用 formbuilder 时的正确格式。
代码片段的屏幕截图 https://prnt。 sc/imbgwE7AlRTr
So I fixed the issue. The problem was how I handled the property declaration of password in the formGroup validator function.
The first code snippet is how I handled the validators which was in the wrong format when using formbuilder.
The second code snippet is the correct format when using formbuilder
Screenshot of code snippet https://prnt.sc/imbgwE7AlRTr
可以忘记忘记将parantheses添加到
{{errorMessageForPassword()}}}}
(我在此处检查了示例: https://material.angular.io/components/form-field/examples/examples/examples#form-field-error )
Can it be that you forgot to add parantheses to
{{errorMessageForPassword()}}
(I checked the example here: https://material.angular.io/components/form-field/examples#form-field-error)