Reputation: 9344
The Angular 5 application works fine but I am getting the following error while building it with production. It also builds fine with ng build
but not with ng build --prod
.
Argument of type '"email"' is not assignable to parameter of type 'string[]'.
The code on the line:
<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>
And form:
private createForm() {
this.form = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email]),
password: new FormControl('', Validators.required)
});
}
Upvotes: 3
Views: 1267
Reputation: 8470
I think that you need to wrap your second 'email'
parameter in an array based on Angular's source code (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); }
I believe the reason that it actually works in your regular build is because although it technically is invalid, the code that eventually gets executed has a call signature that accepts Array<string|number> | string
(line 37-56).
function _find(control: AbstractControl, path: Array<string|number>| string, delimiter: string) {
...
}
Note: your templates are not ran through the typing system in non-AOT mode and hence this doesn't pop up until you do a --prod
build.
Upvotes: 5