The 'push' property is not found within the 'Control' type

I am attempting to create an array that contains arrays within it.

This array is intended for a dynamic form functionality, where the user can add a new section and push the array of control fields to the main array. Angular2 then generates this dynamically.

Unfortunately, I'm encountering the following error message:

Error:(43, 41) TS2339: Property 'push' does not exist on type 'AbstractControl'.

Below is my code snippet:

addDesign(){
    this.addForm.controls['design'].push(this.fb.group({
        name: this.fb.control(null, Validators.required),
        a1: this.fb.control(null, Validators.required),
        a2: this.fb.control(null, Validators.required),
        a3: this.fb.control(null, Validators.required),
        a4: this.fb.control(null, Validators.required),
        a5: this.fb.control(null, Validators.required),
        maxMark: this.fb.control(null, Validators.required)
    }));
}

Constructor function initializing the form:

constructor(private fb: FormBuilder, private auth: Auth, private authHttp: AuthHttp) {
        this.addForm = fb.group({
            name: fb.control(null, Validators.required),
            assignID: fb.control(null, Validators.required),
            design:  new ControlArray([])
        })
    }

I have attempted

(<Control>this.addForm.controls['design']).push
as suggested in Angular2 issue 5871, but unfortunately, it did not resolve the problem.

The framework I am utilizing includes TypeScript and Angular2 beta.17

Answer №1

Instead of using casting for control, consider casting to ControlArray (which should have push declared).

(<ControlArray>this.addForm.controls['design'])

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

Tips for effectively generating a JSON object array in Typescript

Currently, I'm attempting to construct an array of JSON objects using TypeScript. Here is my current method: const queryMutations: any = _.uniq(_.map(mutationData.result, function (mutation: Mutation) { if (mutation && mutation.gene) { co ...

Error: The argument provided cannot be assigned to a parameter that requires a string type, as it is currently a number

Currently, I am in the process of migrating some older websites to TypeScript. However, I keep encountering a type error during the build process. The specific error message is Type error: Argument of type 'number' is not assignable to parameter ...

Is there a way to set up the application that consumes an npm module with a private git url to strictly utilize files exclusively from the module's dist folder?

In my angular application, I encountered an issue with angular-cli not supporting the creation of a library. To work around this, I opted to use the popular git project found at https://github.com/jvandemo/generator-angular2-library for creating my library ...

Creating a React prop type validation that is dependent on the value of another prop

I am in the process of creating a custom React Table component, with the following TableProps structure: export interface ColumnType<ItemType, Key extends keyof ItemType = keyof ItemType> { header: string; key?: keyof ItemType; renderCell: (val ...

Using AngularFire and Firebase to convert observable arrays

My tech stack includes angular CLI, angularFire, and Firebase. I store my data in a real-time database. https://i.sstatic.net/fEbhN.png I retrieve data from Firebase using an observable: //Service.ts import { Injectable } from '@angular/core' ...

Exploring the Google Drive API with Node

Currently, I am utilizing the Google Drive API in NodeJS. Below is the snippet of code I am using to download a file: try { const auth = await authenticate(); const drive = google.drive({ version: 'v3', auth }); drive.files.get( ...

Utilizing the 'create' function in sqlite each time I need to run a query

I've been diving into SQLite within the Ionic framework and have pieced together some code based on examples I've encountered. import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-a ...

What advantages do binary shifts offer in enums?

What do you think about this code snippet? /** * Bitmask of states */ export const enum ViewState { FirstCheck = 1 << 0, // result is 1 ChecksEnabled = 1 << 1, // result is 2 Errored = 1 << 2, // result is 4 ...

How to implement a responsive menu using the onPress attribute of TouchableOpacity

Looking to implement a profile picture upload feature with the ability to choose between getting an image from the camera (using getMediaFromCamera) or selecting one from the gallery (using getMediaFromImageLibrary). I currently have a TouchableOpacity set ...

Utilizing 'Group By' in MySQL PHP to Calculate Averages

How can I calculate the "Average" with "GroupBy" in MySQL? id config_id question rating 1 68 lorem1 3 2 68 lorem2 5 3 69 lorem3 5 4 68 lorem1 NULL ...

Issue verifying the initial certificate in Nodeshift

Currently, I am in the process of deploying an Angular application using nodeshift, but I have encountered the error message "unable to verify the first certificate" whenever I execute the following command: nodeshift --strictSSL=false --dockerImage=buch ...

What is the best way to send various parameters to a component using [routerLink] or router.navigate?

My app-routing.module.ts is configured as shown below: const routes: Routes = [ { path: "branches/:branch", component: BranchesComponent }, // ... ]; In addition, in my app.component.html, I have the following code: <li> ...

Stay Alert: Angular Observable Continuously Monitored for Promise Updates

I am currently working on an angular application that has a connection with a printer. The printer possesses its own status service that is implemented as a promise, providing the printer's current status as a response. However, I am facing an issue w ...

Booking.com's embedded content is experiencing display issues

My current project involves adding a booking.com embedded widget. Initially, when accessing the main page, everything works perfectly - the map and booking widget are visible for ordering. However, if you switch views without leaving the page or closing th ...

Exploring the capabilities of indexing an array within an array in Nativescript

I am working with JSON data retrieved from an API and trying to figure out how to index an array inside an array using Nativescript. JS: cart [{ JS: "_id": "5d3988cd287bad2943686920", JS: "userid": "11E76234942299FCC13FFA163EDC2079", JS: "products": ...

Conversion of string back into byte array is not functioning as expected

Initially, I have a stream which is transformed into a byte array. Later on, this byte array goes through a conversion process to become a string. However, the challenge arises when attempting to revert this string back into a byte array, as shown in the ...

Guide on setting up @types from an NPM module containing the "@" symbol in its title

Installing the node package is easy npm install @gamestdio/timer --save But when attempting to add the corresponding types npm install @types/@gamestdio/timer --save An error occurs Invalid package name "@types/": name can only include URL-friendly ch ...

How to generate a fresh JSON file by extracting unique elements from a JSON array using PHP

I have a JSON object that resembles the following: OBJECT $deals [ { "deal_id": 124563 "merchant_id": 123 "merchant_name": Merchant1 } { "deal_id": 456789 "merchant_id": 123 "merchant_name": Merchant1 } { "deal_id": ...

Retrieving the value of an array from a string pattern using PHP

I have an assumption about an array: Array ( [0] => john [1] => robinson [2] => 27-08-1980 [3] => football [4] => pizza ) I am interested in extracting values from the array usin ...

Error in typography - createStyles - 'Style<Theme, StyleProps, "root"

I'm encountering an error in a small React app. Here is a screenshot of the issue: https://i.sstatic.net/ilXOT.png The project uses "@material-ui/core": "4.11.3". In the codebase, there is a component named Text.tsx with its corresponding styles defi ...