Disabling a specific dropdown within ng-repeat in AngularJS

I've encountered a problem with the ng-repeat in my HTML code:

<div ng-repeat="a in items">
  <div>
    <span>{{a.name}}</span>
  </div>
  <div>
    <select ng-model="a.c_id" ng-options="d.c_id as d.description for d in loclist" ng-disabled="display" ng-change="selected(a.c_id)">
    </select>
  </div>

In my controller, I have the following code:

$scope.display = false;
$scope.selected = function (value) {
    $scope.te = value;
    if ($scope.te == 3) {
        $scope.display = true;
    }        
};

The issue I'm facing is that changing the selection in one dropdown is affecting all other dropdowns. The desired behavior is to only disable or enable the dropdown that was changed. How can I modify this code to achieve the intended functionality?

Answer №1

When using Angular's ng-repeat, new child scopes are created that inherit properties from the parent scope. In your scenario, all scopes within ng-repeat will inherit the display property from the parent scope. This means any changes to the display property will be reflected in all scopes.

To access the current scope within ng-repeat, use this instead of $scope:

$scope.selected = function (value) {
     this.te = value;
     if (this.te == 3) {
         this.display = true;
     }        
};

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

I am trying to access a value saved in a service in Angular 8 component and use it in other services. Can anyone help

Setting a value through a component export class UniqueComponent { constructor(service:UniqueService){ } count =0 ; onRefresh(){ this.service.count = 1; } } Using the value in the service UniqueService{ count:any; doSomething(){ //using count ...

From where does the require.js file originate?

Currently, I am learning Angular 2 from the tutorial available at https://github.com/pkaul/maven-typescript-example. Once I proceed with the 3rd step (mvn jetty:run), a runnable war folder is generated in the example-webapp/target directory. However, I ha ...

res.json responding with altered input unexpectedly

When I use my res.json function, it seems to be altering my data. The data appears correct when logged in the function, but changes inside res.json and I can't figure out why. For example, instead of returning {"unix":"1484600306","naturalFormat":"20 ...

methods for retrieving nested JSON data from an API endpoint

My data has been exported in JSON format { "count":79, "stories":{ "23658975":{ "title":"NOMINATIVO", "description":"BUSDRAGHI PIERGIORGIO", "updated_at":"2013-06-16T18:55:56+02:00", "created_at":"2013-06-16T18:39:06+02:00", "du ...

I am searching for a tool in ThreeJS that functions similar to AxisHelper, possibly a Helper class or utility

While working with Three.js, I have come across many helpful Helper classes that greatly simplify displaying and modifying the scene. However, there is one particular tool that I am struggling to find again. It is similar to the AxisHelper, but it includes ...

Unable to successfully change the Span Class

My webpage has the code snippet below, but it's not functioning as expected. I have tried two methods to change the span's class attribute, but they aren't working. Could someone please help me identify where the issue lies? :) <script l ...

Tips for receiving user input with custom values and assigning them to variables through multiple selection criteria using Jquery

I am encountering an issue with a form that contains multiple selection blocks. I am attempting to extract the values of each block criteria on click in order to send it to a database. However, every time I click on a block, my script retrieves all the val ...

Creating an object positioned to the right side of a div (div:right) is a matter of using CSS positioning properties

While we are familiar with pseudo-classes like :before and :after, have you ever wondered why there is no nav ul li a:left or :right? Do you think it's achievable? I'm open to using HTML5, CSS3, and JavaScript to make it happen. ...

Avoiding duplication when using LoopbackJS and the AngularJS SDK to save models is important

I am working with LoopBackJS AngularJS SDK and have a model for sites (id(pk) integer, name varchar(50), url varchar(100)). However, when I attempt to update the name field and call site.save(), the record ends up being duplicated. If I try to update any ...

"None of the AJAX callbacks are triggered, neither success nor error functions are being executed

document.getElementById('myform').addEventListener('submit', function (e) { // avoid the default action of the submit e.preventDefault(); $(function () { var artist = document.getElementById("artist"); var rows = document.getEl ...

Choosing multiple images using JavaScript/jQuery

Gridster is being used for a webpage, with widgets containing images that can be added and deleted using the "+" and "X" buttons. Current Status Clicking the "+" button opens a modal where multiple images can be selected and added to the widgets by click ...

Using JSF 2.1 for Ajax autocomplete with server search triggered only when user pauses typing

Currently, I am working on developing an autocomplete feature that involves database search based on user input events (specifically onkeyup) in a <h:inputText />. There are two specific preconditions that need to be met for the application to perfo ...

Is it common practice to include a variable in a function with the same name as the function itself?

Is it common practice to use a variable with the same name as the function within the function itself? const sum = function(arr) { let sum = 0; for(let i = 0; i < arr.length; i++) sum += arr[i]; return sum; }; Although this code runs s ...

Setting up a basic testcafe configuration with ES modules

Unique Title When it comes to using ES modules with Testcafe, the documentation may not provide clear instructions on configuring global hooks. There seems to be limited options for configuring Testcafe globally, such as using .json or CommonJS. In my pr ...

Enter key not triggering submission in jQuery UI autocomplete field

I'm currently working on implementing the autocomplete feature following a tutorial, and while it's functioning, I'm facing an issue with submitting the form when the user selects an item and hits enter. Below is the Coffeescript code that I ...

What is the best way to combine text from various group radio buttons?

Here is the JavaScript code I have written: $(function(){ $('input[type="radio"]').click(function(){ var txt = $(this).parent().text(); var $radio = $(this); if ($radio.data('waschecked') == true) { ...

Utilizing DOMPDF in conjunction with jQuery to generate PDF files

Apologies for any language errors in my writing. I am attempting to generate a PDF using a portion of HTML, utilizing jQuery, Ajax, and DomPDF. On the server side, I am using the following code: require_once './dompdf/autoload.inc.php'; if(!em ...

javascript regular expression

Is there a way to extract the text that falls between the first colon and the first period in a string? s:4332Hhj4j32hh432kjh.EF4324rf46543DSVC3443 I attempted using the following regex: /:(.*?)\./g Unfortunately, it still captures the colon and p ...

Converting Epoch time to date in NextJS

In my NextJS app, I have a date displayed in a div. <div>{post.createdat}</div> The date is shown in epoch time (1609553315666), indicating the number of seconds that have elapsed since 1970. I'm wondering if there's a way to conver ...

Triggering transitionend event once with an added if condition

Currently, I have an application of an if statement that examines whether an element contains a style attribute. In the event that the style attribute is absent, it appends inline styling. Conversely, if the style attribute exists, it is removed. Furthermo ...