ngx-custom-validators
ngx-custom-validators copied to clipboard
Custom Validators are not working after updating to Angular 11
IMPORTANT: Please be specific with an example. An issue with
Steps to reproduce and a minimal demo
In a project with Reactive forms, the following lines trigger the error mentioned below
`
import { CustomValidators } from 'ngx-custom-validators';
...
formGroup.addControl('url', new FormControl('', CustomValidators.url);
// Example 2 let myUrl = new FormControl('', CustomValidators.url);
`
- Plunker example Appreciated
Current behavior
I upgraded my project to Angular 11 and while using the custom validators I get the error:
Argument of type 'import("/home/myproject/node_modules/@angular/forms/forms").AbstractControl' is not assignable to parameter of type 'import("/home/myproject/node_modules/ngx-custom-validators/node_modules/@angular/forms/forms").AbstractControl'. Types have separate declarations of a private property '_parent'.ts(2345)
Expected/desired behavior This should work, as I am just using the validators whilst declaring a new FormControl.
Environment information
- OS: Ubuntu 20.04.1 LTS
- Angular Version: 11
- Typescript version: 4.0.5
- npm version: 6.14.8
- Node Version: v14.15.0 Other information
same issue
Also having this issue
same issue
same here
Version 8.0.0
of this package will work with all versions of Angular for the foreseeable future (unless the Angular team changes @angular/forms
drastically).
From version 9.0.0
onwards the package was changed to use ng-packagr
to precompile the TS before publishing to npm, rather than compiling it on the users machine. That's why it breaks with every Angular patch release, because the Angular version is baked into the the npm release. 8.0.0
matches whichever Angular version is installed with your package.json
.
Somewhere between versions 10 and 11 the validators: includedIn
, notIncludedIn
and notMatching
were added. If you can live without those then I recommend sticking with 8.0.0
, nothing else appears to have changed since then.
@rsaenen what was the reason for switching to ng-packagr
? Perhaps it'd be worth reverting this, or finding some hybrid solution using postinstall
Bump?
Version
8.0.0
of this package will work with all versions of Angular for the foreseeable future (unless the Angular team changes@angular/forms
drastically).From version
9.0.0
onwards the package was changed to useng-packagr
to precompile the TS before publishing to npm, rather than compiling it on the users machine. That's why it breaks with every Angular patch release, because the Angular version is baked into the the npm release.8.0.0
matches whichever Angular version is installed with yourpackage.json
.Somewhere between versions 10 and 11 the validators:
includedIn
,notIncludedIn
andnotMatching
were added. If you can live without those then I recommend sticking with8.0.0
, nothing else appears to have changed since then.@rsaenen what was the reason for switching to
ng-packagr
? Perhaps it'd be worth reverting this, or finding some hybrid solution using postinstall
Not working for me!
npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: @angular/[email protected] npm ERR! node_modules/@angular/core npm ERR! @angular/core@"11.2.7" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @angular/core@"^8.0.0" from [email protected] npm ERR! node_modules/ngx-custom-validators npm ERR! ngx-custom-validators@"8.0.0" from the root project
You're probably using NPM 7, which is... a bit controversial, to say the least.