Selecting a single PrimeNG radio button within a form array will dynamically update all other radio buttons in an Angular 11 application

Behavior

When one radio button is checked in a group of FormArray, it triggers all other radio buttons in different groups to be checked as well. Since this is a Form Array, the formControlName values for all radio buttons are the same.

Expected behavior

Choosing a radio button in one group within a Form Array should not affect the radio buttons in any other group.

Minimal reproduction of the issue

https://stackblitz.com/edit/primeng-radio-form-array-selection-issue-rmeptx?file=src%2Fapp%2Fapp.component.html

Answer №1

One of the issues causing this problem is that the radio buttons in the form array all have the same value. To address this, I discovered a workaround using ngModel and the onClick event. It's worth mentioning the necessity of using ngModelOptions when utilizing ngModel within a FormGroup.

public userAgree: boolean = null;

updateUserAgreeFormControl() {
  if (this.reportCommentFormGroup)  
    this.reportCommentFormGroup.get('userAgree').setValue(this.userAgree);
}
<span class="radio-button">
    <p-radioButton name="userAgree" label="Agree" [value]="true" [(ngModel)]="userAgree"      
      [ngModelOptions]="{standalone: true}" (onClick)="updateUserAgreeFormControl()"></p-radioButton>
</span>

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

Developing a Location instance with TypeScript

Struggling with redirecting my app outside of Angular to the logout page. I've tried using $window.location.href, but it doesn't work in Firefox. Someone recommended using $window.location directly, but I'm writing in TypeScript so I need t ...

Struggling to retrieve the header in Angular 6

When setting headers from an Express server written in NodeJS, I use the following code: app.use('/routes', function(req, res, next) { res.setHeader('test', 'test'); next(); ); The headers are successfully sent to th ...

Create an animated hamburger menu using Tailwind CSS and Angular framework

Within my Angular project, I have successfully integrated Tailwind UI to handle the opening and closing of the hamburger menu by utilizing the code below: <header> <div class="-mr-2 -my-2 md:hidden"> <button type="button ...

Ensure your TypeScript class includes functionality to throw an error if the constructor parameter is passed as undefined

My class has multiple parameters, and a simplified version is displayed below: class data { ID: string; desp: string; constructor(con_ID:string,con_desp:string){ this.ID = con_ID; this.desp = con_desp; } } When I retrieve ...

Tips on How to Customize Date Formatting for In-Cell Editing in a Kendo Grid

Currently, I am utilizing In-Cell Editing on a kendo-grid-column. The example provided here demonstrates how you can define the editor attributes for the column. For my specific column, I want to be able to edit dates, so I require a date picker. This can ...

Angular Dialog "Popup" for Updating Information

Currently, I am in the process of developing a "config" page where users can add objects/devices. When a user adds an object, it opens a Dialog window displaying the properties/fields of that particular object. The window includes Save and Cancel buttons. ...

Unable to locate the identifier 'Annotorious'

Currently utilizing NextJS with TypeScript The following script has been added: <Head><link href="/css/bindingbox.min.css" rel="stylesheet"></link><script async type="text/javascript" src="/scripts/an ...

Troubleshooting the issue with the HTTPClient get method error resolution

Currently, I am attempting to capture errors in the HTTP get request within my service file. Below is the code snippet: import { Injectable } from '@angular/core'; import { PortfolioEpicModel, PortfolioUpdateStatus } from '../models/portfol ...

Prevent navigation to non-existent ID parameters in Angular by implementing error handling mechanisms

How can we effectively prevent manual routing to a non-existent parameter in the url, specifically when dealing with paths like 'edit/:id', where id is the parameter? While it works fine for existing ids, the issue arises when inputting a non-exi ...

Is there a tool or resource available that allows you to input an object and receive a TypeScript type or interface representation of that object?

Throughout this year, I've been diving into the world of React and TypeScript. One thing that stood out to me is how challenging it can be to type complex objects. It got me thinking - wouldn't it be great if there was a way or a helper function ...

"Encountering a plethora of server errors when running

After deleting the nodes_module folder and package-lock.json file, I have repeatedly tried to start my npm server in the same location. Additionally, I attempted to run ng update @angular/cli. Any assistance would be greatly appreciated. The errors I am ...

steps for invoking a different component method

I am struggling to figure out how to render the workload component's learningHours method after the setStatusOfUser() method in confirmation.ts. Can someone please help me with this issue? Here is my confirmation.ts component: import { Component, Inj ...

Combining two objects/interfaces in a deep merging process, where they do not intersect, can result in a final output that does not

When attempting to merge two objects/interfaces that inherit from the same Base interface, and then use the result in a generic parameter constrained by Base, I encounter some challenges. // please be patient type ComplexDeepMerge<T, U> = { [K in ( ...

Is it possible to include the term 'public' exclusively within a .ts file in a TypeScript TSLint React environment?

I'm struggling to understand why I am encountering an error in VSCode while working on a react typescript project with tslint setup. The error message states: 'public' can only be used in a .ts file. [Also, I'm wondering why I' ...

Avoiding repetitive logic in both parent and child components in Angular 8

In my parent controller, I have common requests and I also read router params for those requests. However, for the child components, I have different requests but still need to extract the same parameters from the router - resulting in duplicate code. For ...

When a property is removed from a variable in an Angular Component, it can impact another variable

During the iteration of the results property, I am assigning its value to another property called moreResults. After this assignment, I proceed to remove array elements from the testDetails within the moreResults property. However, it seems that the remova ...

Error message: When attempting to redirect to another route, there is a type error with 'this' as it is implicitly assigned the type 'any'

I'm facing an issue with a component I've built using hooks. I want it to redirect to a different route when a function is called and the server response is received. However, my TypeScript is throwing an error: Type error: 'this' impl ...

Ways to access an observable's value without causing a new emit event

Is there a way to retrieve the value of an observable without causing it to emit again? I need this value for an ngClass expression. I attempted to use the tap operator within the pipe to access the values in switchMap, but the value is not being logged. ...

Organizing data in TypeScript

Is there a way to alphabetically sort this list of objects by name using TypeScript? "[{name:"Prasanna",age:"22",sex:"Male",Designation:"System Engineer",Location:"Chennai"}, {name:"Nithya",age:"21",sex:"Female",Designation:"System Engineer",Location ...

Can HTTP_INTERCEPTORS be utilized in a nested lazy-loaded module?

Within my application, I have a nested FooModule inside the AppModule: AppModule: import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.model&apos ...