TypeError: this._validator is not a function
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular/forms in combination with AOT compilation
Is this a regression?
Yes, the previous version in which this bug was not present was: Angular 8 without AOT.
Description
When binding dynamic validator values to an input via [maxlength]="maxLength"
if AOT compilation is enabled the validation is attempted before the validator is created.
An error is logged to the console: ERROR TypeError: this._validator is not a function
.
🔬 Minimal Reproduction
https://github.com/nathanrobinson/angular_ivy_aot_validation_error
🔥 Exception or Error
ERROR TypeError: this._validator is not a function
at MinLengthValidator.validate (VM1588 vendor.js:67057)
at VM1588 vendor.js:60658
at VM1588 vendor.js:60606
at Array.map (<anonymous>)
at _executeValidators (VM1588 vendor.js:60602)
at VM1588 vendor.js:60547
at VM1588 vendor.js:60606
at Array.map (<anonymous>)
at _executeValidators (VM1588 vendor.js:60602)
at FormControl.validator (VM1588 vendor.js:60547)
🌍 Your Environment
Angular Version:
Angular CLI: 8.0.0
Node: 10.14.2
OS: win32 x64
Angular: 8.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.0
@angular-devkit/build-angular 0.800.0
@angular-devkit/build-optimizer 0.800.0
@angular-devkit/build-webpack 0.800.0
@angular-devkit/core 8.0.0
@angular-devkit/schematics 8.0.0
@ngtools/webpack 8.0.0
@schematics/angular 8.0.0
@schematics/update 0.800.0
rxjs 6.4.0
typescript 3.5.1
webpack 4.30.0
Anything else relevant?
The OnChange loop seems to call validate before setting the attributes, and then call it again after setting the attributes.
There are three instances in https://github.com/angular/angular/blob/master/packages/forms/src/directives/validators.ts where this._validator
is called without checking if it is null. This could be resolved for example by rewriting
validate(control: AbstractControl): ValidationErrors|null {
return this.minlength == null ? null : this._validator(control);
}
as
validate(control: AbstractControl): ValidationErrors|null {
return this.minlength == null || !this._validator ? null : this._validator(control);
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:19
- Comments:31 (6 by maintainers)
9.0.0-rc.1 still exist
I have same error, angular 9.0.0-next.8