An issue has occurred in my deeply nested reactive form where I am unable to read the properties of null, specifically the 'controls' property

I have encountered an issue with a deeply nested form that communicates with a REST endpoint upon submission. While the first two levels of the form are functioning properly, I am facing numerous challenges when trying to work with the third level. One particular error that I'm struggling with is: ERROR TypeError: Cannot read properties of null (reading 'controls'). Despite spending a significant amount of time attempting to resolve this issue, I have not been able to find a successful solution. Therefore, I am seeking fresh perspectives to examine the problem.

Below is the response payload that I intend to send:

{
  "appCode": "",
  "accountType": "",
  "emailId": "",
  "IDV": "",
  "emailSubject": null,
  "emailBlurb": null,
  "envelopeRequest": {
    "compositeTemplates": [
      {
        "compositeTemplateId": 13,
        "serverTemplates": [
          {
            "sequence": 93,
            "templateId": ""
          }
        ],
        "inlineTemplates": [
          {
            "sequence": 10,
            "recipients": {
              "signers": [
                {
                  "name": null,
                  "email": "",
                  "recipientId": 41
                }
              ],
              "carbonCopies": [],
              "customFields": {
                "listCustomFields": [],
                "textCustomFields": []
              }
            }
          }
        ]
      }
    ]
  }
}

Everything works smoothly until reaching the "recipients" section, where the process encounters issues. Below is a snippet from my TypeScript file:

// TypeScript code goes here

and here is the HTML code:


// HTML code goes here

If you have insights or suggestions on how to troubleshoot this, your assistance would be highly valued.

Answer №1

It seems the issue lies in how you are accessing the signers form array. Based on your response, the structure of your Reactive form should be:

compositeTemplates (FormArray)

inlineTemplates (FormArray)

recipients (FormGroup)

signers (FormArray)

To access it correctly,

signers(comIndex: number, skillIndex: number): FormArray {
  return this.compositeTemplates()
    .at(comIndex)
    .get(`inlineTemplates.${skillIndex}.recipients.signers`) as FormArray;
}
<ng-container
  *ngFor="let s of signers(comIndex, skillIndex).controls; let i = index"
  [formGroupName]="i"
>
  ...
</ng-container>

Keep in mind that since the signers method now has an additional parameter, it will impact the addSigner and removeSigner methods.

addSigner(k: number, s: number) {
  this.signers(k, s).push(this.envelopeSigners());
}

removeSigner(k: number, s: number, i: number) {
  this.signers(k, s).removeAt(i);
}
<fa-icon
  [icon]="faPlus"
  (click)="addSigner(comIndex, skillIndex)"
></fa-icon>

<fa-icon
  [icon]="faMinus"
  *ngIf="i"
  (click)="removeSigner(comIndex, skillIndex, i)"
></fa-icon>

Check out the demo on StackBlitz for further clarification.

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

Angular interceptor allows the execution of code after the outgoing request has completed its process

In the process of creating a simple interceptor, I have encountered an issue. The interceptor is designed to check if an outgoing request is targeting a specific endpoint type, namely events and favoriteevents. While the interceptor works almost as intend ...

Modal component not displaying properly in ng-bootstrap framework

I'm having trouble getting a modal and its background to display when activated. The elements are being created and destroyed correctly in the developer tools, but they are not visible on the page. I'm trying to replicate the example from this li ...

How come the path alias I defined is not being recognized?

Summary: I am encountering error TS2307 while trying to import a file using an alias path configured in tsconfig.json, despite believing the path is correct. The structure of directories in my Angular/nx/TypeScript project appears as follows: project |- ...

Implement tooltip functionality in ssr chart using echarts

A chart is generated using echarts on the server-side: getChart.ts const chart = echarts.init(null, null, { renderer: 'svg', ssr: true, width: 400, height: 300 }); chart.setOption({ xAxis: { data: timeData }, ...

The Angular 4 application fails to refresh automatically after saving changes in the HTML, CSS, or TS files

Software versions: Angular CLI: 1.6.1 Node: 8.2.1 Operating System: linux x64 Additionally, the devDependencies include: "devDependencies": { "@angular/cli": "1.3.2", "@angular/compiler-cli": "4.0.0", "@angular/language-service": "4.2.4", } ...

programmatically convert a solid link to a specific node into a dashed one using d3

Graph Type Radial Tidy Tree Current Output Initially, I receive a JSON response from the server and use recursion to flatten the JSON. I then utilize d3.tree to visualize the graph displayed below. The Legislation node is designed so that upon double-cl ...

Can TypeScript support the implementation of versatile decorators that can be linked together based on their input and output types?

Within our integration processes, we have developed templated implementations in our codebase that align well with the "pipe and filter" pattern in my opinion. These "components" can be structured in the following formats: class Component1<In, Out, Xi ...

We are unable to create a 'Worker' as Module scripts are not yet supported on DedicatedWorkers in Angular 8

Error An error has occurred in the following files: node_modules/typescript/lib/lib.dom.d.ts and node_modules/typescript/lib/lib.webworker.d.ts. Definitions of various identifiers conflict with those in other files, leading to modifier conflicts and dup ...

The Angular overlay panel remains open consistently

I recently developed an Angular component similar to p-overlaypanel, but I'm facing an issue where it remains open for every item I click. What I actually want is for only one overlay panel to be clicked and shown at a time - if I click on another ove ...

What could be causing my Ionic button to not initialize in the expected state while using ngIf with a boolean property connected to an Ionic checkbox?

I'm currently in the process of setting up a list of ingredients with checkboxes and conditional buttons, but I'm facing some challenges with the default state. Ideally, I only want the button to be visible when the checkbox is unchecked so that ...

Exploring the Use of throwError in Angular 7 with RxJs 6.x

I'm having trouble using the second parameter (error) in my subscriber, it doesn't seem to be working properly. Here is the code for my Observable: return Observable.create(obs => { cognitoidentityserviceprovider.adminCreateUser(params, fu ...

Angular component failing to refresh data upon service response

Within my Angular component, I have integrated badges onto certain icons. These badge numbers are fetched from an api upon entering the page, utilizing ionViewWillEnter(). Once the api response is received, the outcome is stored in a local variable, which ...

Best practices for updating the value of a specific key within an object that contains recursion in JavaScript/TypeScript

I have a tree component that uses the following data structure type TreeNode = { id: string, parentId: string, renderer: () => React.ReactNode, expanded: boolean, children?: Array<TreeNode>, } Now, I am looking to add functionality for ...

What is the process for extracting the elements of an array fetched from a service in Angular 2?

Currently, I am learning Angular 2 + PrimeNG and going through a quick start project available at the following link: https://github.com/primefaces/primeng-quickstart The project is a CRUD application and it functions flawlessly. The data is neatly displa ...

Establishing a connection pathway for communication among components in Angular

I am faced with a situation where I have two components, CompA and CompA5, that are 3 or 4 levels apart. I need to establish a means of communication between these components. For instance, I want component CompA to send an event to CompA5, receive some d ...

How to send form group in Angular when the enter key is pressed

When I press the submit button on a form, it sends a request to the database to filter data in a grid. However, I also want the form to submit when the enter key is pressed. HTML <form [formGroup]="bmForm" (keyup.enter)="onSearchClic ...

Retrieving the active slide's property in MongoDB using Ionic React

I'm attempting to display a collection field based on the ObjectId linked to another collection in MongoDB. I have three collections: Users: { "_id" : "115ds1f4sd55fe1e51fds5f4", "name" : "Sam", &qu ...

Error message in Angular 2 Routing: Unable to locate main outlet for loading 'AppComponent'

I am currently working on developing an Angular application and have created a login component. Upon successful login, the user should be directed to the dashboard page. I have built a dashboard component for this purpose. To handle navigation in Angular ...

A combination of MVC6, tsd, and typings has proven to be

Given that TSD has been officially deprecated, I am looking towards the future and seeking guidance on how to use typings in the MVC6 framework. Any advice or tips would be greatly appreciated. I attempted following a tutorial from the typings website, wh ...

Mapping an array of Type T in Typescript using typings

Suppose we have a type T: type T = { type: string, } and we create a function that takes an array of T and returns an object where the keys are the values of each T.type and the values are objects of type T. const toMap = (...args: T[]) => args.red ...