i have an form array which i want to limit to only 5 input elements generated by user and my form has following definition
createskillForm()
{
this.skillForm=this.formBuilder.group({
skills:this.formBuilder.array([this.createskillFeild()],Validators.minLength(1),Validators.maxLength(5))
});
}
i have tried making changes with minlength but it is showing the following error in the console :- RROR in src/app/components/com-profile/com-profile.component.ts(47,89): error TS2345: Argument of type 'ValidatorFn' is not assignable to parameter of type 'AsyncValidatorFn | AsyncValidatorFn[]'. Type 'ValidatorFn' is not assignable to type 'AsyncValidatorFn'. Type 'ValidationErrors' is not assignable to type 'Promise | Observable'. Type 'ValidationErrors' is not assignable to type 'Observable'. Property '_isScalar' is missing in type 'ValidationErrors'. what i can do to limit adding user only five skills ?
if (this.myFormArray.controls.length >= 5) return;this example will vary with each particular case, but you get the idea. If this is a method, do tell me to add it as an answer! Hope it helps.