Choose not to tie to ng-bind data that is repeated

My goal is to include a select list inside an ng-repeat loop, allowing for multiple instances of the select list to be displayed with the user selecting a value for each one. The code I am using is:

      <div class="actionList" ng-repeat="selectedAction in inputDevice.selectedActions">
        <select class="inputAction" ng-model="selectedAction" ng-options="action as action.fields.name for action in inputDevice.fields.baseDevice.fields.inputs">
          <option value="">
            Select Action
          </option>
        </select>
        <button class="btn btn-primary" ng-click="addAction(inputDevice, $index)">
          +
        </button>
      </div>

While it works well overall, I have encountered an issue where upon selecting an option from the select list, it reverts back to the default state without actually selecting the chosen option (the selected action's state also remains unchanged). I've attempted modifying the property within selectedAction, changing ng-model="selectedAction.value" instead of just selectedAction, but with no success. Interestingly, if I alter ng-model="selectedAction" to something like ng-model="foo", it works smoothly and I can see the select value bound to the new foo variable in the scope. Why is it that I cannot bind to the repeated element?

Answer №1

Consider providing a jsfiddle link for easier troubleshooting. It appears that the issue may be related to setting the ng-model to a primitive (string) instead of an object, causing the value to disappear upon change. If inputDevice.selectedActions were an array of objects, this issue might have been avoided.

Another suggestion to possibly address the issue (without a jsfiddle link for confirmation) is to set ng-model="foo{{$index}}" to create a new scope variable with the loop index, potentially resolving the problem.

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

Trouble assigning the 'data' attribute to the 'Object' tag using jQuery. [Limited to IE8]

I have encountered a problem when creating an object element dynamically in jQuery to display some content. The code functions perfectly in all browsers except for IE8. Here is the code snippet: j$(document).ready(function(){ j$('.ob ...

Leveraging the content delivery network for react-select in a react.js project

I'm having trouble using react-select with cdn. I attempted to download the cdn for react-select but keep encountering an error stating that 'select is not defined'. I also tried downloading the zip package for react-select, but I am unsure ...

What are some alternatives to using multiple slot transclution in an Angular 1.5 component?

In the process of constructing a panel component using angular 1.5, I am looking to embed some markup into this template (which has been simplified): <div class="panel"> <h1>{{ $ctrl.title }}</h1> <div ng-transclu ...

Is there a way to transform a personalized jquery event listener into an angularjs listener?

A custom event listener was created using jQuery for an angularjs component. The event is triggered by a non-angularjs library. $( "#myDiv" ).on( "CornerstoneImageRendered", function(e) { // buisness logic }); The element myDiv is a div that belongs t ...

I'm struggling to locate the target for the WaitTextForPresent command in Selenium IDE when testing an AJAX website. Can anyone offer

As a newcomer to JavaScript, Selenium IDE, and web development, I am currently learning about a website that uses an AJAX application at . I am trying to utilize the WaitTextForPresent command to detect when a unique chat message appears, but I am unsure o ...

Choose multiple options, with a maximum limit of 2 selections

I am currently working with a multiselect feature for various subjects. I would like to limit the selection to a maximum of 2 options and disable the rest. Additionally, if a user deselects an option, it should become available again for selection. <se ...

JavaScript appendChild method not functioning properly with dynamically created image elements in JavaScript code

I recently encountered an issue while working on a website project. I was trying to create an img element using JavaScript, but ran into a problem when I tried to add the src attribute and then use the appendChild function. I'm unsure if I am missing ...

What are the steps to take in order to successfully deploy an Express server on GitHub Pages?

I heard that it's possible to host an Express server on GitHub Pages, but I'm not sure how to do it. Is the process similar to deploying a regular repository on GitHub Pages? ...

Tips for styling the chosen option in a dropdown menu with <ul> and <li> tags

I am having trouble logging the selected dropdown value to the console in this code snippet. HTML <div class="dropdown"><button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" ...

Setting up VideoJS Flash backup

Due to Firefox's restriction on using an .mp4 file in the <video> tag, I am required to utilize the Flash fallback option on my VideoJS player. When it comes to Chrome, Safari, and IE, I can customize my VideoJS player via JavaScript to perform ...

Trigger a Vue method using jQuery when a click event occurs

I'm attempting to attach a click event to an existing DOM element. <div class="logMe" data-log-id="{{ data.log }}"></div> ... <div id="events"></div> Struggling to access external Vue methods within my jQuery click handler. A ...

Node.js client-side code

Hi all, I am currently exploring Nodejs and experimenting with setting up a server-client connection using sockets. The server side seems to be functioning properly, but I am encountering some difficulties with the client side connection. I would appreciat ...

AngularJS 1 scripts being compiled by Gulp in the wrong sequence

Have you ever encountered this issue before? Whenever I run my scripts through GULP, the console starts throwing errors, indicating that my directives and/or controllers are not being registered properly. To address this, I experimented by adding the app v ...

How can I use jQuery to automatically change the background color of each item to match the color of the next

I have a list with 4 items, each item has a specific background color set in the style attribute. <div class="list"> <div style="background: red"></div> <div style="background: blue"></div> <div style="background: gr ...

Is there a way to programmatically retrieve and play multiple videos in a continuous loop directly from a designated folder using HTML?

I am looking to create a program using HTML/AngularJS that can dynamically retrieve videos from a folder without the need to manually list them. <video id="myvideo" width="320" height="240" controls style="background:black"> <source class="act ...

Mobile browser viewport dimensions

My Nexus 5 shows a width of 360 when I visit . I am aware that there is a difference between my phone's resolution and the browser width. Despite this understanding, I encounter a problem when attempting to create a function that triggers at a width ...

Data from AngularFire not displaying in my list application

While going through tutorials on the Angular website, I encountered a roadblock while attempting to create a list that utilizes Firebase for data storage. Strangely, everything seems to be functional on the Angular site, but clicking on the "Edit Me" link ...

The HierarchyRequestError in Javascript related to XML

var xmlRoot = "<root></root>"; var firstChildNode = "<firstChild></firstChild>"; var parser = new DOMParser(); var xmlDom = parse.parseFromString(xmlRoot, "text/xml"); var xmlChildNode = parse.parseFromString(firstChildNode, "text/ ...

Interacting with a non-stringified object displayed in the browser console using TestCafe

Upon receiving a page that logs an object to the console, I encountered an issue when trying to access this object using getBrowserConsoleMessages(). The object appeared as the String "[object Object]" in the console, making it impossible for me to parse ...

Node text: three.js and ngraph.tree working together

I am currently working on developing a 3D network (network of people) for a browser using three.js and ngraph. The graph has been successfully created, but the nodes are currently displayed as squares. My goal is to replace these squares with the text "nod ...