The validator function in FormArray is missing and causing a TypeError

I seem to be encountering an error specifically when the control is placed within a formArray. The issue arises with a mat-select element used for selecting days of the week, leading to the following error message:

What might I be doing incorrectly to trigger this error?

vendor.js:65387 ERROR TypeError: this.validator is not a function
	    at FormControl._runValidator (vendor.js:106921)
	    at FormControl.updateValueAndValidity (vendor.js:106882)
	    at new FormControl (vendor.js:107326)
	    at FormBuilder.control (vendor.js:111089)
	    at FormBuilder._createControl (vendor.js:111149)
            ...
        

The data structure returned inside the 'element' object accessed through 'professionals.forEach' looks like this:

element: {
		daysService: [2, 3],
		endService: "",
		id: "45ySYbmImayrgv7teqWr",
		startService: "",
		name: "Name professional",
		rooms: [],
	};
	

Snippet from form.component.ts:

this.weekDays = [
	    { label: 'Sunday', value: 0 },
	    { label: 'Monday', value: 1 },
	    { label: 'Tuesday', value: 2 },
	        ...
	];

	this.professionals
	  .pipe(takeUntil(this._unsubscribeAll))
	  .subscribe(professionals => {
	  	if (!professionals) return;
	  	this.setProfessionalsUnity(professionals);
	});

	private _buildForm(): void {
	    this.form = this._formBuilder.group({
	      professionals: this._formBuilder.array([])
	    });
	}
            ...

	public addGroupProfessional() {
	    return this._formBuilder.group({
              id: [''],
	      name: [''],
	      rooms: [''],
	      daysService: [''],
	      startService: [''],
	      endService: ['']
	    });
       }
       

Excerpt from form.html:

<form [formGroup]="form">

 	   <mat-accordion formArrayName="professionals">
	       ...
 	  </form>

Answer №1

Give this method a shot:

    daysUtilized: [[2, 3]]

Answer №2

To properly structure the arrays, you must wrap them accordingly. When dealing with existing objects, follow this example:

// @ts-ignore 
entity.property = [entity.property];
fb.group(entity);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can Angular's change detection be triggered by a change in @Input?

As of now, I am immersing myself in guides and tutorials on Angular's change detection. There are some statements that are quite perplexing to me. Therefore, I am seeking confirmation or clarification. The default Change Detection is activated "every ...

a callback may seem like it's not a function, but in reality, it is

This question might seem simple, but I'm struggling to grasp the concept of callbacks, especially in NodeJS. My issue arises when trying to retrieve data from MySQL, something that is usually straightforward in most programming languages: In my rout ...

Angular 9: The instantiation of cyclic dependencies is not allowed

After transitioning from Angular 8 to Angular 9, I encountered an issue with a previously functioning HTTP communication service. The error message now reads: Error: Cannot instantiate cyclic dependency! HttpService at throwCyclicDependencyError (core ...

Angular - utilizing subscription within a for-loop to determine completion

Below is the code I am using to generate sticky notes: update() { this.tab3Service.updateStickyNote(this.stickyNoteUserConnection.stickyNote).subscribe(response => { const updatedStickyNote: StickyNote = response; for(let i = 0; i < this.stickyNo ...

Merge two observables together to create a single observable that emits values from both sources. Only one observable will emit values

I am looking to combine two observables of type T[] obtained from httpservice. I have tried using forkJoin and zip, but they both return an Observable of type [T[], T[]]. However, I want to receive an object of type T[] as shown in the following code snip ...

Enumerate the names of the private properties within the class

I am working on a problem where I need to use some of the class properties as values in a map within the class. In the example below, I have used an array instead of a map because when a property is marked private, it is not included in the keyof list. How ...

What is the process for deconstructing errors from the RTK Query Mutation Hook?

Currently, I am utilizing redux toolkit query for handling my data fetching API. One issue that I have encountered is with error handling. When an error is returned from the server, it comes in as an object with nested data. However, when trying to access ...

When trying to use TypeScript with next.js, encountering an unexpected token `?` error is not

Having an issue with next.js, the command npm run dev keeps failing due to a syntax error related to an optional property in a tsx file: Syntax error: Unexpected token 44 | 45 | type State<T_HT> = { > 46 | ghostHighlight: ?{ | ...

Encountering a navCtrl problem in Ionic 3 while attempting to utilize it within a service

I am currently working on a feature to automatically route users to the Login Page when their token expires. However, I am encountering an issue with red lines appearing under certain parts of my code. return next.handle(_req).do((event: HttpEvent< ...

Accessing data from a Class in Angular 2

I have developed a class to store the default settings for my application. However, I am unsure of how to retrieve data from this class and integrate it into my HTML. I attempted using an observable, but it doesn't seem to be effective. Here is a gli ...

Achieve a seamless redirection to the 404 component in Angular without altering the browser URL, while ensuring that the browsing

Whenever my backend sends a 404 error (indicating that the URL is valid, but the requested resource is not found, such as http://localhost:4200/post/title-not-exist), I need Angular to automatically redirect to my NotFoundComponent without altering the URL ...

The Viewchild element is currently nonexistent

(Angular 9) I'm having issues with using ViewChield() in my code. Here is a snippet of the HTML I am working with: <input type="text" pInputText [(ngModel)]="code" #inputStudent/> Here is what I have in my TypeScript file: ...

Running NG BUILD from Gulp can be done using either child-process.spawn or by disabling all output in child-process.exec

Have you come across a similar question like this Call "ng build" from inside a gulp task? I have found a way to successfully build Angular using Gulp in order to prevent overflowing the output buffer. Here's how I achieved it: const child ...

What is the advantage of utilizing the ng-idle library for monitoring user idle status when we have the ability to create custom JavaScript code to track inactivity based on keyboard and mouse events?

I have implemented a method to detect user idle time using mouse and key events as shown below. @HostListener('window:keydown', ['$event']) @HostListener('window:mousedown', ['$event']) @HostListener('window:mou ...

Challenge with Angular date selection component

I am currently utilizing ngbdatepicker in my form. I want to save the date separately and retrieve it as shown below. <input class="form-control ngbfield custom-form-control" required [ngClass]="{'is-invalid':f.touched && birthDay.inv ...

Customize the text color of select list options in Angular 5

Is there a way to style the foreground colors of select list options differently in this dropdown code? <select id="tier" class="form-control" [(ngModel)]="tierId"> <option *ngFor="let m of tierList" value="{{m.tier}}" > {{m.option ...

Unlock the power of Angular Component methods even when outside the Angular library with the help of @ViewChild()

In my Angular library, there is a component called AComponent which has its own template, methods, and properties. Once the Angular library is packaged, it becomes available as a NuGet package for other projects to utilize. @Component({ selector: ' ...

Angular 6 issue: Bootstrap 4 carousel indicators not responsive to clicks

I am currently working on incorporating a Bootstrap 4 carousel into my application, but I seem to be encountering issues with the indicators. Ideally, clicking on any of them should navigate you to the corresponding photo, similar to this example: https:// ...

Develop a Java RESTful server with an Angular 5 client that utilizes POST and PUT syntax for communication

Currently, I am in the process of learning the HTTP REST/CRUD protocol in an attempt to establish communication between a Java RESTful servlet and an Angular5 client. I have successfully implemented the GET and DELETE functionalities, however, I am encount ...

Exploring the Method of Utilizing JSON Attribute in typeScript

How to access JSON attributes in TypeScript while working on an Angular Project? I'm currently in the process of building an Angular project and I need to know how to access JSON attributes within TypeScript. test:string; response:any; w ...