Having an issue in Reactive Form where the nested formControlName is not capturing the value

How can I store a value in a nested reactive form when the nested formgroup is not accepting the value?

this.signupForm=new FormGroup({
  username:new FormControl(),
  email:new FormControl(),
  jobDetail: new FormGroup({
    code:new FormControl(),
    post:new FormControl()
  })
});

For the complete code, please visit https://stackblitz.com/edit/angular-zgw8tn

Answer №1

Here are a couple of minor errors to watch out for:

The correct attribute is formGroupName instead of FormGroupname. When dealing with posts, make sure to use formControlName instead of FormcControlName.

For further information on reactive forms in Angular, please refer to https://angular.io/guide/reactive-forms

Answer №2

Remember, it's written in camel case as formGroupName and everything else looks great!

<div class="container">
  <div class="row">
    <div class="col-xs-12 col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2">
      <form [formGroup]="signupForm" (ngSubmit)="onSubmit()">
        <div class="form-group">
          <label for="username">Username</label>
          <input type="text" id="username" formControlName="username" class="form-control">
        </div>
        <div class="form-group">
          <label for="email">Email</label>
          <input type="text" id="email" formControlName="email" class="form-control">
        </div>
        <div formGroupName="jobDetail">
        <div class="form-group">
          <label for="code">Employee Code</label>
          <input type="text" id="code" formControlName="code" class="form-control">
        </div>
        <div class="form-group">
          <label for="post">Employee Post</label>
          <input type="text" id="post" formcControlName="post" class="form-control">
        </div>
        </div>
        <button class="btn btn-primary">Back</button>
        <button class="btn btn-primary pull-right" type="submit">Submit</button>
      </form>
    </div>
  </div>
</div>

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

What is the best way to increase the height of an image beyond the limits of its container, causing it to overlap with other elements

My challenge involves creating a horizontal scrolling list of movie posters. I want the posters to grow in size when hovered over, expanding outside of their container and overlapping other elements. I attempted to use 'position: absolute' on the ...

When trying to invoke an Angular function from a JavaScript function, it is returning as undefined

When attempting to invoke an Angular function from a JavaScript function, I am encountering an issue where it is displaying as undefined. Below is an example demonstration I have created: import { Component, NgZone, OnInit } from '@angular/core&apo ...

Issue: angular2-cookies/core.js file could not be found in my Angular2 ASP.NET Core application

After spending 2 hours searching for the source of my error, I have decided to seek help here. The error message I am encountering is: "angular2-cookies/core.js not found" I have already installed angular2-cookie correctly using npm. Below is the code ...

Polling with RxJs, handling errors, and resetting retryCount with retryWhen

I am currently working on setting up a polling strategy that functions as follows: Retrieve data from the server every X seconds If the request fails, show an error message: "Error receiving data, retry attempt N°"... And retry every X seconds for a maxi ...

What is the best way to arrange a list in Angular2 using AngularFire2's FirebaseListObservable?

Looking to retrieve all users from a Firebase realtime database and organize them based on a score property. I managed to achieve this by using the variable users: FirebaseListObservable<any[]>; however, encountered the following errors: Type & ...

The latest update for angular-devkit/build-angular (version 0.13.4) has brought a new issue with the configuration output. It seems that there is an unrecognized property

After upgrading a project from angular-devkit/build-angular v0.11.4 to v0.13.4, an error is now appearing: Invalid configuration object. Webpack has been initialised using a setup that does not align with the API schema. - configuration.output contains a ...

Encountering issues with loading series on Highchart in Angular 4 due to duplication restrictions

I recently integrated highchart into my Angular 4 application, but I encountered a problem where the same series is being loaded twice. The issue seems to be related to the addSeries method, which is triggered by the @Input() set stressTestResults declarat ...

Unusual conduct exhibited by a 16th version Angular module?

I've created a unique component using Angular 16. It's responsible for displaying a red div with a message inside. import { ChangeDetectionStrategy, Component, Input, OnInit, } from "@angular/core"; import { MaintenanceMessage } ...

Is it possible to reuse a variable within a single HTML tag when using Angular 2?

I encountered a strange issue with Angular 2 that may be a bug. I noticed that I couldn't print the same variable in a template twice within the same HTML tag. When I tried to use the following code, it resulted in error messages. <div class=" ...

Prevent the necessity of typecasting in mocked TypeScript imports

When I import a mocked function, Typescript doesn't recognize that Jest changes the import to a mock. As a result, I have to cast the imported function in order to utilize mock methods such as mockReturnValue. jest.mock('../myImport'); impo ...

How does TypeScript interpret the data type 'a' | 'b' as a string?

As a beginner in TypeScript, React, and English, I apologize for any confusion. I have written a function like this: interface ObjectAttrUniqueState { editVisible: boolean; currentId: number; selectedUnique: number[]; name: string; desc: string; ...

What are the benefits of precompiling my Typescript project for production instead of just running it directly with ts-node?

Many people recommend precompiling production builds. However, the reasoning behind this advice is not clear to me. What potential issues may arise from running a project in production using node --loader ts-node/esm src/server.ts ? ...

Is there a way to deactivate the click function in ngx-quill editor for angular when it is empty?

In the following ngx-quill editor, users can input text that will be displayed when a click button is pressed. However, there is an issue I am currently facing: I am able to click the button even if no text has been entered, and this behavior continues li ...

Error: Unable to establish connection - Asp.Net Core and Angular 10

Currently, I am following an Asp.net tutorial along with using the Angular server with CORS package integration. My main goal is to make a post request: // POST: api/Trackers // To protect from overposting attacks, enable the specific properties y ...

Having trouble resolving Typescript module references

My dilemma revolves around two Typescript react modules known as moduleA and moduleB. My attempt involves utilizing a component called Button.tsx from moduleA by exporting it in moduleB and referencing this component through moduleA. These are the steps ...

TSX is throwing an error: "No matching overload found for this call."

Just starting out with React and TypeScript here! I tried passing the propTypes into a styled-component and ran into this error message: Oh no, there's an issue with the overloads. Overload 1 of 2 seems to be missing some properties. Overload 2 of ...

The value of type 'X' cannot be assigned to type 'Y' or 'undefined'

In my code, there is a component that requires a prop with an enum value: export enum AType { some = "SOME", word = "WORD", } const MyComponent = (arg: AType) => {} When I try calling this component like so: <MyComponent ar ...

Uh oh, the executor encountered an issue while trying to run [/bin/sh -c npm run build]. The error code returned was

I'm currently in the process of dockerizing my MEAN stack application. (I recently delved into Docker and began learning about it only 2 days ago). Upon executing docker compose up, I encountered the following error: #22 ERROR: executor failed runnin ...

I'm having trouble with the @Input() binding in my custom directive and it's not working as intended

Example Link - Creating a Custom Directive import { Directive, ElementRef, Input } from '@angular/core'; @Directive({ selector: '[appCustomDirective]', }) export class CustomDirective { @Input('appCustomDirective') bord ...

Tips for sidestepping the need for casting the class type of an instance

Looking to develop a function that can accept an argument containing a service name and return an instance of that particular service, all while ensuring proper typing. Casting the instance seems necessary in order to achieve the desired result. To illust ...