您在需要流的地方提供了无效的对象。您可以提供 Observable、Promise ReadableStream、Array、AsyncIterable 或 Iterable

发布于 2025-01-17 20:33:02 字数 1595 浏览 5 评论 0原文

[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>

enter image description hereenter image description hereUsing 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惜醉颜 2025-01-24 20:33:02

所以我解决了这个问题。问题是我如何在 formGroup 验证器函数中处理密码的属性声明。
第一个代码片段是我在使用formbuilder时处理错误格式的验证器的方式。

  passWord: ['', Validators.required, Validators.minLength(6)],

第二个代码片段是使用 formbuilder 时的正确格式。

 passWord: new FormControl('', [Validators.required, Validators.minLength(6)]),

代码片段的屏幕截图 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.

  passWord: ['', Validators.required, Validators.minLength(6)],

The second code snippet is the correct format when using formbuilder

 passWord: new FormControl('', [Validators.required, Validators.minLength(6)]),

Screenshot of code snippet https://prnt.sc/imbgwE7AlRTr

绿光 2025-01-24 20:33:02

可以忘记忘记将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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文