Troubleshooting: Issue with nesting ng-model within radio buttons in ng-repeat loop

Hi there, I'm facing an issue while attempting to showcase a group of radio buttons within an ng-repeat loop. It appears that the initial values from the fields bound to ng-model are not being recognized by the input.

When providing a simple array to ng-repeat, the buttons display with their correct initial values. However, once a nested ng-repeat is introduced, only the last item in each list initializes with a value.

You can view my code on CodePen:

https://codepen.io/alokraop/pen/JXLZBp

I'm uncertain about what mistake I might be making. I'm ensuring that the name attribute for each radio button is unique within its group.

Your assistance would be greatly appreciated.

Answer №1

The problem lies in the inability to interpolate an Angular value into the attribute name. By removing the name attribute from our HTML code, we are able to achieve the desired outcome. Refer to the example below:

<div ng-app="sample">
  <div ng-controller="sampleController as sample">
    Single ng-repeat:
    <div ng-repeat="queue in sample.queues">{{queue.name}} status:
      <input type="radio" name="queue-{{$index}}" ng-model="queue.condition" value="hooked" /> hooked
      <input type="radio" name="queue-{{$index}}" ng-model="queue.condition" value="unhooked" /> unhooked
      <input type="radio" name="queue-{{$index}}"  ng-model="queue.condition" value="partial" /> partial
    </div>
    <br />
    Nested ng-repeat:
    <div ng-repeat="qm in sample.qms">
      {{qm.name}} queues:
      <div ng-repeat="queue in qm.queues">{{queue.name}} status:
        <input type="radio" ng-model="queue.condition" value="hooked" /> hooked
        <input type="radio" ng-model="queue.condition" value="unhooked" /> unhooked
        <input type="radio" ng-model="queue.condition" value="partial" /> partial
      </div>
    </div>
  </div>

</div>

To dynamically include a name, consider utilizing an Angular name directive like this: Dynamic form name attribute <input type="text" name="{{ variable-name }}" /> in Angularjs

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

What is the best way to seamlessly transition layers from one location to another as the mouse exits and re-enters the window?

I have been working on refining a parallax effect to achieve a seamless transition between two positions based on where the mouse exits and enters the window. In the JSFiddle example provided, there is a slight 'pop' that I am looking to replace ...

Nodemon is failing to automatically re-run the changes I've made in my local codebase

Recently, I developed a basic node function that simply outputs "hello world." When I ran the script using the command line node myfirst.js, it successfully displayed the message in the browser. Then, I decided to install nodemon so that it would re-exec ...

Executing a series of tests using Postman

Is running multiple requests in a postman script feasible? I have an endpoint: http://localhost/gadgets/{id}/buy This endpoint sets a flag in a gadget object/entry based on its id. With hundreds of gadgets, can I use a shared file of ids to create and run ...

Sending Disabled Form Field Input Value in Angular 2 POST Request

I'm working on a form with an email field that I want to populate using interpolation. However, I also want to prevent users from changing the email address once it's displayed. To achieve this, I tried adding the disabled attribute to the input ...

What is the best way to pass the setState value to the useEffect hook?

After watching a Youtube video, I took on the challenge of creating my own recipe app using React.js as a beginner. I have been troubleshooting for the past 2 days and seem to have hit a roadblock. The issue lies in passing the value of my state to the use ...

Not sure how to configure the settings for Firebase Firestore within the admin.firestore module

When trying to set an option at admin.firestore, I couldn't find the set method. It should be done like this: const settings = {timestampsInSnapshots: true} admin.firestore.settings(settings) However, I encountered a TypeError: Firestore.settings is ...

Meteor Infinity: the astronomy .save functionality seems to be malfunctioning

Encountering an issue where I am receiving a "post.save is not a function" error when trying to use the .save() function with astronomy v2. The error occurs when attempting to call the .save() function to insert a new document into the database using a Met ...

Using indented, multi-line logging in a NodeJS environment can help to

I'm looking for a way to display objects that have been printed with JSON.stringify() in the console, specifically within the context of a Mocha test suite output. While my tests are running, I want the object log lines to be indented further to the ...

Manipulate the contents of an HTML class using Javascript to substitute text with an empty string

Is there a way to create a JavaScript function that can remove text upon clicking from multiple HTML fields with the same class? I am facing an issue where my function is not clearing the data in the target field when "Yes" is selected in the trigger. Re ...

Leverage the power of AJAX to fetch and display controller action results on the current

this is my code of the view I've set up a dropdown menu with options that have values like /ControllerName/ActionName. Upon clicking one of the dropdown values, it redirects me to another page with the selected ControllerName and ActionName. However ...

updating react state based on filtered redux properties

Just starting out with react & redux and running into some issues with filtering insights (articles, case studies, reports). My goal is to filter by industry, but I'm struggling to update the state with the filtered insights. InsightsPage.js con ...

How to insert an image into a placeholder in an .hbs Ember template file

I'm looking to enhance a .hbs template file in ember by incorporating an image. I am not a developer, but I'm attempting to customize the basic todo list app. <section class='todoapp'> <header id='header'> & ...

Error: pos variable is not defined

I encountered a TypeError: pos is undefined while running the code below. $(document).ready(function() { var s = $("#col-scroll"); var pos = s.position(); $(window).scroll(function() { var windowpos = $(window).scrol ...

Preventing opening while closed through the OnClick event

I have the following OnClick function: const [open, setOpen] = useState(true); and onClick={() => setOpen(!open != true)} The goal is to "close when open" and "remain closed if already closed". The current code achieves the second part but not the fir ...

What are the best practices for utilizing the "this" keyword with fetch?

After extensively studying ES6 documentation and the changes it brings, I am eager to incorporate the new oop syntax along with modern libraries such as fetch. Below is the code snippet I have been working on: apiCall(url, thisAlias=this){ fetch(url). ...

What might be the reason my $q.defer().resolve is not functioning properly?

I have noticed an interesting behavior in my code. When I define a promise in the service and return it back (promise1 in this case), it does not resolve at all. However, when I define the promise in the controller (promise2), it works perfectly fine. Why ...

Transmitted only JSON data instead of using multiform data with jQuery Ajax

When I use jQuery Ajax to send a JSON object, it ends up being interpreted as 'multiform' instead of pure JSON. How can I make sure my request is sent as a pure JSON object and not multiform? var demo = new Array("One", "Two", "Three"); $.ajax ...

Getting access to the current row along with its value within an AngularJS application

Seeking guidance on how to edit and remove a row in angularjs as I am new to it. In my dynamic table, rows are inserted dynamically with links for editing and deleting. I am looking to edit a row upon clicking the edit link. HTML Code: <div ng-contro ...

When trying to serialize elements from a form loaded by Firefox using AJAX, encountering difficulties due to

Visit the live version of this at . When prompted for a formId, input BroadRunTrack2013. Follow by adding an item to cart and entering player name information (you can use random data for now). Select the Runner's Hat, choose color/size, specify quant ...

Show the MySQL query results in a pop-up alert box

I need assistance with querying a MySQL database for certain results using PHP and then displaying the result in an alert dialog box through JavaScript. I am able to connect to the database, query the data successfully, and display it on a PHP page. Howeve ...