Utilizing ngModel with the radio group component from the API in Angular

Here's the code.

component.html

<form nz-form [formGroup]="taskFormGroup" (submit)="saveFormData()">
    <div nz-row *ngFor="let remark of checklist">
              <div nz-col nzXXl="12" *ngFor="let task of remark.tasks" style="padding: .5rem;">
                <div nz-row nzGutter="6" nzType="flex" nzAlign="middle" style="border-left: 5px solid rgba(167, 0, 51, 0.5);">
                  <div nz-col nzSpan="8">
                    <label [textContent]="task.name"></label>
                  </div>
                  <div nz-col nzSpan="8">
                    <nz-form-item>
                      <nz-form-control>
                        <nz-radio-group formControlName="radiostatus" [(ngModel)]="radio" (ngModelChange)="onChangeStatus($event)">
                          <label nz-radio nzValue="passed">Passed</label>
                          <label nz-radio nzValue="failed">Failed</label>
                        </nz-radio-group>
                      </nz-form-control>
                    </nz-form-item>
                  </div>
                </div>
              </div>
            </div>
  </form>

component.ts

checklist = [
    {
      "id": "txv3vvBr8KYB",
      "assetType": {
        "id": "1fKBO4w0XHg7H",
        "code": "PRD",
        "name": "Printing1"
      },
      "tasks": [
        {
          "id": "1fKBO4w0XHg7H",
          "name": "Task 1",
          "description": "Check oil spill"
        },
        {
          "id": "ESOSA6aCrOER",
          "name": "Sample1",
          "description": "Desc1"
        }
      ]
    },
    {
      "id": "EwQciw9whx6B",
      "tasks": [
        {
          "id": "1nU7uASqfvLPD",
          "name": "TASK8888",
          "description": "DESC8888"
        },
        {
          "id": "EwQciw9whx6B",
          "name": "TASK9999",
          "description": "DESC9999"
        }
      ]
    }
  ];

When selecting 'passed' or 'failed', selecting it on one item should not affect another item. For example, if 'passed' is selected on the first item, it should not automatically select 'passed' on the second item.

Currently, when 'passed' is selected on the first item, it also affects the second item by selecting 'passed' there as well.

Answer №1

Make sure to use unique ngModel bindings for each form control in your code, rather than the same name for all of them.

component.html

<div nz-row *ngFor="let remark of checklist; let  i = index">
      <div nz-col nzXXl="12" *ngFor="let task of remark.tasks" style="padding: .5rem;">
        <div nz-row nzGutter="6" nzType="flex" nzAlign="middle" style="border-left: 5px solid rgba(167, 0, 51, 0.5);">
          <div nz-col nzSpan="8">
            <label [textContent]="task.name"></label>
          </div>
          <div nz-col nzSpan="8">
            <nz-form-item>
              <nz-form-control>
                <nz-radio-group [(ngModel)]="task.id" (ngModelChange)="onChangeStatus($event)">
                  <label nz-radio nzValue="passed">Passed</label>
                  <label nz-radio nzValue="failed">Failed</label>
                </nz-radio-group>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
      </div>
 </div>

Check out this example on StackBlitz

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

Using jQuery or Javascript to implement a drop-down list filter functionality

For the past two months, I've been struggling to figure out how to create a drop-down menu to filter content on the site I'm building for my boss. Despite countless searches online, I haven't found a solution that works. This is the only iss ...

Converting JavaScript code into PHP syntax

I'm curious about code organization. The original code in this snippet is functioning properly: <?php if (isset($_POST['submit'])){ ... ... $invalidField = 2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD ...

Looking to showcase the outcome of the Procedure invocation when I made the call?

{ "isSuccessful": true, "resultSet": [ { "name": "pradeep", "password": 123, "timestamp": "2014-04-08T12:58:45.000Z" }, { "name": "dileep", "password": 1234, "timestamp": "2014-04-08T13:00:52.000Z" } ] } I have ...

Appcelerator Titanium issue: Facebook Graph API showing empty Friends list

Having trouble with the Facebook connection using Titanium. When I send a request to Facebook using Graph API, I only receive an empty result: SUCCESS; {"data":[]} This is the code I'm using: Ti.App.fb.requestWithGraphPath('me/friends' ...

Having multiple upload forms on a single page with PHP, AJAX, and jQuery is not functioning as expected

I'm on the hunt for a jQuery-AJAX image uploader that supports multiple instances of the form on a single page. Do you have any recommendations? Here's my scenario: I have a front-end page where users can update their profiles. Upon loading the ...

Implementing Various Conditions in ng-if Using AngularJS

I have a scenario in my AngularJS application where I need to display different buttons based on the value of type. If type === 'await_otp', then I should display two buttons (resend OTP and cancel), if type === 'submitted', then only t ...

Guidelines for returning an object upon finishing the .map function within a promise-based function in Node.js

While working on server-side code using nodejs, I have encountered an issue with the .map() method inside a Promise. The problem is that the method returns a value before the .map() function completes its execution successfully. Here's the snippet of ...

Tips on how to ensure that an onClick JS function only runs when radio buttons are selected

I have implemented the formslider library for a form on my website. In the demo, the slide transitions to the next set of questions based on a click event triggered by radio buttons (answers). However, when I attempted to include checkboxes for users to s ...

The $.post function is failing to return a successful response

Utilizing select2 to gather multiple member names in a single input field, I have implemented the following ajax code within my form.php file: $('#student_vgroup').submit(function(event){ event.preventDefault(); var name = $( ...

The overflow phenomenon similar to what can be found in Photoshop

I'm curious if there's a way to create an overlay effect similar to what you see in Photoshop or Illustrator. I have a background picture and a colored div in front of it. I'd like to add an overlay effect to the front div that looks more i ...

Having issues with my JavaScript timer - seeking assistance in troubleshooting the problem

Trying to set a timer for my little game, but facing some difficulties. The timer causes the balance to randomly increase from 0 to 13000 + some extra amount. <script> var coins = 0; var speed = 1; </script> <center> <h4> ...

Tips for incorporating a datepicker into your Angular 2 application

In my HTML file, I have defined the following code: <span id="datepicker" (click)="ShowDate()"> <i class="fa fa-calendar " aria-hidden="true" style="margin-top: 20px;margin-left: 20px;" >< ...

Handling an HTML Form without the Submit Button using VeeValidate

I've implemented a form handler using its composable feature in my <script setup>: const { submitForm, resetForm, handleSubmit, meta } = useForm() function save() { // Want to submit the form here submitForm() // Not working showSaveSnac ...

Using JSX is only possible with the addition of the '--jsx' flag, specifically when the value of "jsx" is set to "react-jsx"

typescript error message: Trouble with JSX: Must use the '--jsx' flag.ts(17004) Switching tsconfig.json's jsx to react-jsx resolves the JSX issue. However, running yarn start changes it back to react-jsx again. react-scripts has been upd ...

Can a placeholder be created for Next.js Image without using blur effect?

Currently, I am utilizing Next.js in my projects. The Next.js Image component includes placeholder and blurDataURL attributes which work seamlessly together. However, when attempting to incorporate a custom SVG placeholder (converted to base64) the result ...

How come my div doesn't stick together with the other div while moving?

I am trying to figure out how to make the blue "shield" div cover the red "button" div after 3 clicks successfully. It seems like no matter what I do, the positioning is always off. I've played around with the randomplace variable, but nothing seems t ...

Looking to extract the expiration date from an x509 certificate?

I am currently engaged in a project that involves retrieving and displaying certificate information from an Azure integration account using Angular/Typescript. One of the requirements is to show the decoded public certificate to users to extract important ...

interactive symbols in a reorganizable tree structure

I have been developing a customizable tree list for our users to arrange their website content. It allows them to add and rearrange pages by dragging and dropping. Each list item includes the page name and three icons (lock, visible, and edit). The challe ...

Oops! Looks like there was an error: $http is not defined

I'm facing a challenge with implementing $http in the AngularJS framework. I've gone through various other resources on this issue, but I can't seem to figure out what I'm doing incorrectly. Any assistance would be highly appreciated. T ...

the conditional operator used without assigning the result to a variable

Exploring conditional operators on html canvas, I am seeking a streamlined approach to dynamically change stroke color based on conditions. Online examples have not provided a satisfactory solution in a single line of code. Currently, without using a cond ...