The FormControl is currently presenting ",required(control)" within its value field

Upon loading my form, the default values in the input fields are set to:

,required(control) { return isEmptyInputValue(control.value) ? { 'required': true } : null; }

The template structure of my form is as follows:

<form [formGroup]="SvgFormData" (ngSubmit)="onSubmit()">


    <section class="text-control-section">

        <label class="control-label">
            <p class="articleText">title:</p>

            <input class="text-control" type="text" formControlName="title" />

        </label>

        <label class="control-label">
            <p class="articleText">graphic id:</p>

            <input class="text-control" type="text" formControlName="graphicId" />

        </label>

    </section>


</form>

This component receives the FormGroup data from its parent component through an @Input(). My goal is to create an app for parsing and saving SVG to a database in JSON format. The parser returns a data object that I pass into a custom function to generate the entire FormGroup while populating the values of the FormControls. Despite being completed technically, I turn it into a form to enable editing before saving it to the database. Here is the main function:

export function CreateGraphicObjectForm(data?: OvaadSvgDataObject): FormGroup{
    let graphicObjectForm: FormGroup = new FormGroup({
      title          : new FormControl([(data ? data.title     : ''), Validators.required]),
      graphicId      : new FormControl([(data ? data.graphicId : ''), Validators.required]),
      viewBox        : CreateViewBoxForm((data ? data.viewBox : undefined)),
      coreAttributes : new FormArray([]),
      coreStyles     : new FormArray([]),
      elements       : new FormArray([])
    });


    if(data.coreAttributes.length > 0){
      data.coreAttributes.forEach((a: OvaadGraphicAttribute)=>{

        let coreAttrArray: FormArray = graphicObjectForm.get('coreAttributes') as FormArray;

        coreAttrArray.push(CreateAttributeForm(a));

      });
    }

    if(data.coreStyles.length > 0){
      data.coreStyles.forEach((a: OvaadSvgStyleProperty)=>{

        let coreStyleArray: FormArray = graphicObjectForm.get('coreStyles') as FormArray;

        coreStyleArray.push(CreateStylePropertyForm(a));

      });
    }

    if(data.elements.length > 0){
      data.elements.forEach((a: OvaadGraphicObject)=>{

        let elementArray: FormArray = graphicObjectForm.get('elements') as FormArray;

        elementArray.push(CreateGraphicElementForm(a));

      });
    }

    return graphicObjectForm as FormGroup;
  }

The controls for title and graphicId are defined within this function level, omitting the need to share other functions and interfaces used. This is how the form is structured before passing it to my component, where I attempt to link them in the template. Any insights on why I'm encountering this issue and suggestions for improvement based on my use case?

Answer ā„–1

The issue at hand involves creating FormControls. Consider implementing the following solution -


title: new FormControl((data ? data.title : ''), [Validators.required]),
graphicId: new FormControl((data ? data.graphicId  : ''), [Validators.required]),

Answer ā„–2

The issue I encountered was that I had mistakenly been using:

this.myReactiveForm.setValue({
  field: ['', Validators.required]
})

when I should have been using:

this.myReactiveForm.setValue({
  field: ''
})

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

Implementing group validation with Angular

What is the proper validation method for a form group control with code length containing decimal fields? Currently, my code is as follows: this.control = new FormControl(val, [Validators.required, Validators.maxLength(items.CodeLength)]); However, I am ...

What is the most efficient way to dynamically load a script file before proceeding with the rest of the code execution?

In my Angular home.component.ts file, I have added the script loading code as shown below: export class HomeComponent { constructor() { this.loadDynamicScript(); } public loadDynamicScript() { var script = document.createElement(&a ...

Enhancing Type Safety in TypeScript with Conditional Typing within Array reduce()

In my codebase, I've implemented a function named groupBy (inspired by this gist) that groups an array of objects based on unique key values provided an array of key names. By default, it returns an object structured as Record<string, T[]>, wher ...

Having trouble deploying my Angular application on Heroku

I have been attempting to deploy my Angular 6 application on Heroku. Despite building the project and following all deployment steps, I am encountering the following result on Heroku: Furthermore, the Heroku logs display the following: Upon testing the d ...

Why is it that PowerShell cannot execute Angular commands?

Recently, I started diving into Angular and encountered an issue using PowerShell in Windows. Every time I run an angular command like: ng new new-app or ng serve I keep getting this error message: ng : File C:\Users\< username >\ ...

Is the communication between Angular service and component failing when using ngFor?

I am currently using Angular to create a video game page. When a specific title is clicked, the id is sent to make an API call with that specific id. I am able to retrieve the data in the selected-games component where I intend to use it, but when I use ng ...

Having trouble loading static files in Django Angular framework? Specifically, images stored in the assets folder returning a

In my Angular project, I have an assets/image folder within the src directory where all my images are stored. Various components and child components in my app use these images like <img src"../../../assets/image/test.png">. After building my Angula ...

Issues with relocating function during the NgOnInit lifecycle hook in an Angular 2 application

Currently, I am facing an issue with my Angular 2 app where the data sometimes lags in populating, causing a page component to load before the information is ready to display. When this happens, I can manually refresh the page for the data to appear correc ...

Taking ASP.NET Core 2.0 with Angular to CloudFoundry

Currently, I am facing an issue while working on an app in CloudFoundry (CF). Whenever I push my code into CF, I encounter an error indicating that NodeJs is not installed. [APP/PROC/WEB/0] ERR [1] Ensure that Node.js is installed and can be found in one ...

Executing a Playwright test against various projects or URLs within a single test run

I've been grappling with this problem for the past few days. I've tried a few workarounds, but none of them have worked as expected. What I need is to run Playwright tests against multiple URLs. Currently, running tests in a single project works ...

Troubleshooting problems with Angular 6 update through the command "ng update"

https://i.stack.imgur.com/LuPSs.png I am currently in the process of upgrading from Angular version 5 to 6. When using the "ng update" command, I encountered a problem that is shown in the attached screenshot. Can someone guide me on how to resolve this ...

I'm looking to enhance my Angular app by implementing a submenu that features various tabs

Currently, I am following a tutorial available at this link to achieve my desired outcome. However, I am facing some challenges because my tabs are not located in the root component. In my scenario, I have a contract with certain properties that I want to ...

Sign out of Google and Facebook accounts using Angular framework

Upon logging in to both Facebook and Google using this package, I am facing an issue with signing out. Even after using the code provided below, I cannot seem to sign out of Google and Facebook: this.authService.signOut(); sessionStorage.clear(); Any as ...

What is the best way to switch the CSS class of a single element with a click in Angular 2

When I receive data from an API, I am showcasing specific items for female and male age groups on a webpage using the code snippet below: <ng-container *ngFor="let event of day.availableEvents"> {{ event.name }} <br> <n ...

Angular 2 TypeScript: How to effectively sort an array

Iā€™m currently exploring how to implement array filtering in Angular 2 with TypeScript. Specifically, I am trying to filter data for a search bar in Ionic 2. While the list in the template successfully displays the data, I am encountering difficulty getti ...

The 'palette' property is not found on the Type 'Theme' within the MUI Property

Having some trouble with MUI and TypeScript. I keep encountering this error message: Property 'palette' does not exist on type 'Theme'.ts(2339) Check out the code snippet below: const StyledTextField = styled(TextField)(({ theme }) = ...

Error in WebStorm: Troubleshooting HTML file issue in Angular application

I encountered an error in WebStorm while working on a new project where I was testing a form. The issue only arises when I run ng serve, although no errors are reported and the application runs smoothly. To troubleshoot, I tried deleting my node_modules f ...

Guide to creating a SVG component using typescript in a React application

I have a component where I am passing SVG icons props as an array containing my SVG component data. However, TypeScript is showing me an error while working with Material UI. Type '{ key: number; data: { id: number; icon: ReactNode; }; }' is not ...

Is it possible to close a tab while the chrome extension popup is still active?

I am currently developing a Chrome extension that reads the content of the current tab and performs a heavy task on the backend. If I were to close the tab while the process is ongoing, how can I allow the user to do so without waiting for the task to fi ...

Leveraging IntersectionObserver to identify the video in view on the screen

Our Objective I aim to implement a swipe functionality for videos where the URL changes dynamically based on the ID of the currently displayed video. Challenges Faced Although I managed to achieve this with code, there is an issue where the screen flashe ...