question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:19
  • Comments:31 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
gurachancommented, Nov 9, 2019

9.0.0-rc.1 still exist

7reactions
igorkemackcommented, Sep 30, 2019

I have same error, angular 9.0.0-next.8

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 Typescript: TypeError: this.validator is not a function
I had this error when I was binding an array of values in form builder the wrong way. What I did: fb.group({items: [1,...
Read more >
TypeError: this.validator is not a function - Ionic Forum
validator is not a function. I'm iterating through an array of records to dynamically create formGroups for the frontend. I've achieved this in ......
Read more >
Angular Example This Validator Is Not A Function - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
error typeerror: this.form.get is not a function
The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of...
Read more >
AbstractControl - Angular
Disabled controls are exempt from validation checks and are not included in the ... The new validator function or functions to add to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found