Is it possible to make a distinctive choice from the dropdown menu?

I need help with my html page that has 10 dropdowns, each with options 1 to 10. How can I assign options uniquely to each dropdown? For example, if I select option 1 in dropdown 1, that option should be removed from the other dropdowns. If I deselect an option, the number should be added back to the dropdown options.

Answer №1

Check out the following code snippet:

HTML:

<div ng-controller="MyCtrl">
<select ng-model='selectedNumber' ng-change="adv(selectedNumber);" ng-options='number for number in numbers'></select>
num:   {{selectedNumber}}
<select ng-model='selected' ng-options="number for number in num"></select>
num:   {{selected}}
<button ng-click="add()" >add</button>
</div>

JavaScript:

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {    
  $scope.numbers = [1,2,3,4,5,6,7,8,9,10];
  $scope.num = angular.copy($scope.numbers);
  $scope.selectedNumber = $scope.numbers[0];
  //$scope.selected = $scope.num[0];

  $scope.add=function(){
  $scope.num = angular.copy($scope.numbers);
}

 $scope.adv = function(selectedNumber){
 $scope.num = angular.copy($scope.numbers);
 // $scope.selected = $scope.numbers[selectedNumber];   
 var a = $scope.num.splice(selectedNumber-1, 1);  
}

 $scope.num = angular.copy($scope.numbers);
} 

I hope this is the code you were looking for.

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

Is there a way to restrict access to my website to only be opened in the Chrome browser?

Is there a way to prevent my web application from loading when the link is opened in browsers other than Chrome? Can this be achieved using Javascript or Java? I want to restrict the usage of my web application to only Chrome. Any assistance would be appre ...

Guide on exporting a reducer from a Node module built on React Redux

I am currently working on a project that requires importing a component from an external node module. Both the project and the component utilize React and Redux, and I intend for them to share the same store. Below is a snippet of the reducer code for the ...

Creating a customized store locator using JSON data in WordPress for Google Maps API

I'm currently seeking a customized solution to implement a store locator using the Google Maps API within WordPress. Although there are numerous WordPress plugins available, I prefer a more tailored approach. Here are the specific requirements: ...

Nuxt.js Development Script Fumbles

Recently, I've been working on a website using Nuxt.js and have been really enjoying the process. However, I'm encountering an error that's puzzling me whenever I attempt to run $npm run dev: 0 info it worked if it ends with ok 1 verbose cl ...

Setting line chart data for Chart.js

Can you help me troubleshoot an issue I'm facing with creating a dataset for a line chart in Chart.js? Despite having an array of objects, the dataset isn't rendering correctly and I end up with two line charts instead of one. What could be causi ...

Getting an HTML element by its ID that was passed from the ng-init directive in Angular can be achieved

When I use ng-click, I am able to retrieve the html element by id. However, when I use ng-init, I only get null. Please take a look at my codepen here. HTML Code: <script type="text/javascript"> var memId = "bb7de28f-0f89-4f14-8575-d494203acec7 ...

The issue with the AngularJS component layout engine is that the fxLayoutAlign attribute set to "stretch" is not

It seems that when using the angular/flex-layout along with angular/material2, the fxLayoutAlign="stretch" directive is not functioning correctly. However, the directives fxLayoutAlign="start" and fxLayoutAlign="end" are working as expected. You can see th ...

Uploading multiple file attachments with Angular.js and Rails

Currently, I am experimenting with Angular to upload multiple files from a form. However, the issue I am facing is that the rails application is only receiving one file in the params hash. The scenario involves creating an article via a form, and this art ...

Having trouble executing partial views with node.js and AngularJS?

I have been working on my AngularJS application and everything functions correctly when I browse it. However, I've encountered an issue while trying to configure Express. The main page displays fine, but when I click on the hyperlinks to load partial ...

What is the method for substituting one text with another using two-way data binding?

I implemented two different cases in my Mat-Table. When there is no data, the user will see a message saying "No Data Found". However, if the user enters text in the filter search, the "No Data Found" message should be hidden and replaced with the entered ...

Issues arising from Vue, Yup, and i18n integration for translations

I am currently developing a Vue.js App (using Vite) where I have integrated Vee-validate with Yup for form validation, as well as i18n for message translation. However, I am experiencing an issue where the custom errors defined in the schema do not dynamic ...

Gridsome's createPages and createManagedPages functions do not generate pages that are viewable by users

Within my gridsome.server.js, the code snippet I have is as follows: api.createManagedPages(async ({ createPage }) => { const { data } = await axios.get('https://members-api.parliament.uk/api/Location/Constituency/Search?skip=0&take ...

How can I create a script in Discord.js that automatically sends users their information upon joining the server?

I'm currently working on developing a code that automatically sends the user's avatar, username, ID, account creation date, server join date, and status when they join The structure of the code looks something like this: module.exports = (Discor ...

Using Node.js to handle reading files and dealing with undefined or null values

The get method is responsible for receiving a userid with an initial total number of points defined in the stcok.json file, along with various transactions stored in another file. Below are some sample entries from the stock JSON: [ { "user" ...

Tips for improving the speed of loading infinite scroll pages

I am currently working on scraping over 100k rows from the provided URL. The data goes back approximately a month, loading in batches of 7-8 rows at a time. My current approach involves using a macro to scroll down the page slowly, which is effective but ...

Using AngularJS ng-model to select options in a dropdown menu with WebDriver

In the following code snippet, an AngularJS based dropdown menu is implemented: <select _ngcontent-c1="" class="form-control ng-pristine ng-valid ng-touched"> After opening the list, I attempted to select a variable from this list using the code be ...

Transclusive directives and nested components

Within my directive, I am binding a property like this: scope: {modelVar: "="} The directive template then uses this variable: <input ng-model="modelVar"> However, when I transclude this directive within another directive, the input lives in a ch ...

Transforming a Formdata object into a JavaScript array

Greetings everyone! Is there a way in JavaScript to convert this data structure: { Control[0].Eseguito: "true" Control[0].Id:"2" Control[0].Nota:"" Control[1].Eseguito: "true" Control[1].Id:"2" Contr ...

Storing a byte array in a local file using JavaScript: A Step-by-Step Guide

Recently, I encountered an issue while working with an openssl certificate. Specifically, when I tried to download the certificate from my API, it returned byte arrays that I needed to convert to a PEM file in order to access them through another API. The ...

Creating a Vue application without the use of vue-cli and instead running it on an express

Vue has an interesting feature where vue-cli is not necessary for running it without a server. Initially, I thought otherwise. The Vue installation page at https://v2.vuejs.org/v2/guide/installation.html mentions using a script under CDN. <script src=&q ...