gpt4 book ai didi

angular - 如何修复 Argument of type '"email "' is not assignable to parameter of type ' string[]' 错误?

转载 作者:太空狗 更新时间:2023-10-29 18:15:13 27 4
gpt4 key购买 nike

Angular 5 应用程序工作正常,但在使用生产构建它时出现以下错误。它也可以通过 ng build 正常构建,但不能通过 ng build --prod 构建。

Argument of type '"email"' is not assignable to parameter of type 'string[]'.

上线代码:

<mat-form-field>
<input matInput placeholder="Email" formControlName="email" required>
<mat-error *ngIf="form.hasError('email', 'email') && !form.hasError('required', 'email')">
Please enter a valid email address
</mat-error>
<mat-error *ngIf="form.hasError('required', 'email')">
Email is <strong>required</strong>
</mat-error>
</mat-form-field>

和形式:

private createForm() {
this.form = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email]),
password: new FormControl('', Validators.required)
});
}

最佳答案

我认为您需要包装第二个 'email'基于 Angular 源代码 ( line 520-526 ) 的数组中的参数:

/**
* Returns true if the control with the given path has the error specified. Otherwise
* returns false.
*
* If no path is given, it checks for the error on the present control.
*/
hasError(errorCode: string, path?: string[]): boolean { return !!this.getError(errorCode, path); }

我相信它在您的常规构建中实际工作的原因是因为尽管它在技术上是无效的,但最终执行的代码具有接受 Array<string|number> | string 的调用签名。 (line 37-56)。

function _find(control: AbstractControl, path: Array<string|number>| string, delimiter: string) {
...
}

注意:您的模板不会在非 AOT 模式下通过输入系统运行,因此在您执行 --prod 之前不会弹出。构建。

关于angular - 如何修复 Argument of type '"email "' is not assignable to parameter of type ' string[]' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49568026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com