Tips for deactivating a specific control item within an array in Angular 9

I am working on a form that contains a formArray.

  InitialFrom(): void {
this.addElectricMoneyFG = this.fromBuilder.group({
  hasAccountNumber: [this.showMoreInfo],
  moreAccountInfo: ['', null],
  description: [''],
  locales: this.fromBuilder.array([]),
  published: [false]
})

The formArray structure looks like this:

selectedLanguage(langId): FormGroup {
return this.fromBuilder.group({
  languageId: [langId],
  name: [''],
  moreAccountInfo: ['']
})

}

My goal is to disable the moreAccountInfo field in the formArray when a toggle is clicked.

This was my attempted code:

this.f.hasAccountNumber.valueChanges.subscribe(check => {
  this.showMoreInfo = check;
  if (check) {
     this.f.locales['controls'][0]['controls']['moreAccountInfo'].enabled;
  } else {
    this.f.locales['controls'][0]['controls']['moreAccountInfo'].enabled;
  }
  this.f.locales.updateValueAndValidity();
  this.cdRef.detectChanges()
})

However, it resulted in an error:

this.f.locales.controls[0].controls.moreAccountInfo.disabled is not a function

Answer №1

Here is the recommended method to follow.

 (<FormArray>this.testForm.get("locales")).controls[0].get('moreAccountInfo').disable()

If you wish to disable the entire form at index 0.

(<FormArray>this.testForm.get("locales")).controls[0].disable()

Click here for a demonstration

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

Program that extracts information from interactive controls

One of my challenges involves working with pages that have dynamic controls, where I never know the types or quantities of controls present. My goal is to create a script that can extract text from a text area when it's clicked. Although I initially b ...

Troubleshooting NativeScript 5: Uncovering the iOS Memory Woes of Crashes and Le

Check out this link for more information: https://github.com/NativeScript/NativeScript/issues/6607 Software Stack: NativeScript 5 Angular 7 Demo repository: https://github.com/reposooo/ns-out-of-memory This issue is based on a similar problem i ...

The overlay lingers on the page even after the modal successfully redirects to the search

My goal is to implement a modal that prompts users to input their search term and find recipes with a specific ingredient. I have successfully achieved this by using simple redirection. However, upon redirecting to the search results, the overlay remains o ...

Tips for incorporating a Spotify-style play button using CSS into a table row

Hey there! I recently attempted to customize my button like Spotify. I wanted the table row to display a play button when hovered over, and when clicked, the image would change. https://i.sstatic.net/aJIna.jpg After seeking advice from another fiddle an ...

Page refreshing in Angular 5 consistently redirects to the home page instead of staying on the current page

I am experiencing an issue with the navigation on my application. When I navigate to routes like getEmp-by-id or page-not-found and hit refresh, the application automatically redirects me back to app-home. However, I would like it to stay on the same pag ...

Utilizing ngx-pagination for repetitive instances of a single component

I have encountered an issue with the ngx-pagination library in my reusable data table component. While it works perfectly for a single instance, using it multiple times causes the pagination to only function on one of the components. Is there a way to make ...

Can the AngularJS icon adapt to different lists?

I'm currently developing in AngularJS / Jade and I need to implement functionality where an icon changes when a user clicks on something. The code I have right now looks like this: a(onclick='return false', href='#general', data-t ...

Transforming a string into an onclick event handler using JavaScript

Looking for assistance with assigning the literal content of the variable ElementAction to an onclick handler of a different HTML element. Despite attempting HTMLElement.onclick = ElementAction, it doesn't seem to be working as expected. Any guidance ...

It appears that Type 'MenuItemsProps' does not contain a property named 'map'. This might be causing the error message 'Property 'map' does not exist on

Recently, I delved into learning TypeScript and decided to convert my React code into TypeScript. However, I encountered an issue that left me stumped. I tried passing a state through props to a component with a defined value, hoping that the state would b ...

The persistent loading animation in AngularMaterial Autocomplete does not come to an end

Exploring AngularJS and AngularMaterial: Currently, I am delving into the world of AngularJS and experimenting with AngularMaterial. To put it to the test, I decided to create a sample based on the code provided in the documentation (check codepen). My ap ...

The React app is divided into two separate applications

I'm currently working on splitting my main React application into two separate applications under one host. The split needs to be done using routes. Here is the routing for my main app: (routing code will go here) This is my MobileApp component: (mo ...

Using AJAX to search through paginated pages is quite simple and effective

Currently, I have developed a JavaScript script that filters names within a list. However, a problem has arisen with pagination - as the list paginates, I am unable to retrieve names without refreshing the page. Is there a way to use AJAX to access and dis ...

When TypeScript error "ts(18004)" occurs, it is because of the object properties within all Prisma DB

I am currently in the process of verifying if a user's email already exists. To achieve this, I am utilizing Prisma Client's findUnique method. Below is the code snippet I have implemented: const userWithEmail = await prisma.user.findUnique({ ...

Error message in Angular 2/NativeScript: Unusual issue indicating a component that has not been imported into any module, despite being imported in the main module

Currently, I am working on a small barcode scanner app that includes a SettingsComponent for setting a local IP. The app compiles without any issues, but when deployed on a genymotion emulator, I encounter the following error message. It seems like the app ...

A guide on distinguishing between two dates in Ionic3 using either date-fns or Moment libraries

How can I calculate the difference between two dates to determine the end of an employee's service? Similar Question: What is the best way to find the day difference between two dates using Ionic 3? I am looking for a solution on how to get the exac ...

Comparing two string dates in mongoose: A guide

I am trying to retrieve data between two specific dates in my Schema. transactionDate : String Here is the function I am using to get data between two dates: async getLogsByDate(start, end) { return await this.logModel .find({ date: { $gte: sta ...

The index type in TypeScript's keyof function is overly broad

Sorry if this question has been addressed before, but I'm having trouble finding the right search terms. Feel free to correct my question if necessary. This is what I have: type RowData = Record<string, unknown> & {id: string}; type Column&l ...

Tips for resolving this JavaScript conditional statement

Can you help me understand how to make this if statement true and show an alert message? I'm unsure about the significance of 0x4, 0x3, and 0x05. How can we modify this code to trigger the alert? var Ft32A = [ function (x,y) {return x+y}, f ...

Struggling to understand the reason behind the malfunction of my promise array

I am currently tackling a project that involves running a series of promises and then pushing their results to an array within the .then() portion. However, I am encountering an issue where even though the promises are providing result values, nothing is b ...

Deployment failure due to undetected development keys in gitignore

I have a TypeScript-coded Express server with three files for keys in the compiled and pre-compiled code: /// dev.ts - development keys const keys = { googleClientSecret: "GOOGLE_KEY", mongoURI: "mongodb+srv://MONGO_K ...