Transferring dynamic <select> values to a list demonstrates its worth

Whenever the button is clicked, a new select option is added. On removal, the last member of the array is deleted. The goal now is to transfer the selected value to a list below.

This snippet showcases the code in question:

  $scope.langInput = {
    count: 3,
    values: [1, 2],
    add: function() {
        this.values.push(this.count);
        this.count += 1;
        console.log(this.values);
    },
    remove: function() {
        this.values.pop();
        this.count -= 1;
        console.log(this.values);
    }
};

Here's a working demo of the provided code. There's still an issue with moving the selected option to the <ol> list. Any tips would be greatly appreciated.

Answer №1

One way to write the code for a select element is like this:

<select ng-model="n.selected" ng-change="onChange(n.selected, $index)">

It's important to note that in this code snippet, the variable langInput.values must contain a list of objects and not integers.

$scope.langInput = {
        count: 3,
        values: [
          {
            id:1,
            selected: "eng"  
          },
          {
            id:2,
            selected: "eng"
          }
          ],
        add: function() {
            this.values.push({id:this.count,selected: "eng"});
            this.count += 1;
            console.log(this.values);
        },
        remove: function() {
            this.values.pop();
            this.count -= 1;
            console.log(this.values);
        }
    };

    $scope.onChange = function(value, index){
      $scope.langInput.values[index].selected = value;
    }

Check out the Demo Plunker here

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

Arrange divs adjacent to each other without any gaps in between

My HTML code includes elements from Twitter Bootstrap and AngularJS framework. <div class="item item-custom-first"> <select class="form-control" style="display:inline; float:right" ng-model="requestdata.units ...

Node.js client encounters ENOBUFS error due to excessive number of HTTP requests

Currently, I have the following setup: An end-to-end requests system where a node.js client communicates with a node.js server. However, the issue arises when the client fails with an ENOBUFS error in less than a minute. client: (function(){ var lo ...

I am unable to utilize the Web Share API for sharing a file within my React app written in TypeScript

Trying to launch a WebApp for sharing files has been quite a challenge. After some thorough research, I stumbled upon the Web Share API which seemed like the perfect solution based on standard practices. The documentation provided a clear outline of how it ...

Tips for displaying a removal option and eliminating an uploaded document

I need assistance in implementing file uploading using dropzone.js. I am struggling to find a solution on how to delete uploaded files. Here is the code snippet: index.php <div class="container"> <div class="file_upload"> <form action= ...

Tips for employing duplicated HTML on a webpage

I have developed a main menu for my website using html and css. It seems cumbersome to manually copy and paste this menu into every single file or page on the website whenever I make edits. Is there a way for this main menu to automatically appear on every ...

What is the best way to load a model and save it to a variable for future use?

One issue I'm facing involves loading a model in this manner: var Beech; var loader = new THREE.JSONLoader(); loader.load( "./models/trees/Beech/Beech.json", function( geometry, materials ) { Beech = addMorphTree(geometry,materials,0.5); }); and uti ...

Having trouble getting ng-repeat to work properly alongside Bootstrap collapse?

Using a bootstrap 4 card to create a blog post. When the View Comments link is clicked, a collapsed div within the card-footer should open to display all comments. The collapse functioned correctly with hard coded html and dynamic data {{blog.title}} until ...

Combining two ng-model inputs in Angular for seamless data integration

New to Angular and seeking some guidance. I currently have two input fields, one for the area code and the other for the number. // Input field for area code <input area-input type="tel" required="true" name="area" ng-model="employee.home.area">&l ...

Difficulty with obtaining .responsetext in AJAX and PHP

On my real estate website, I have a form for users to 'Add a Property'. Although I will implement form validation later on, here is the current html/js code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR ...

The jQuery AJAX response consistently comes back empty

Hello, I'm currently working on creating an HTML form and I need to validate it before submitting the form action. However, when I use AJAX to respond, I keep receiving a blank message. Can anyone help me with this issue? $(function(){ $("#ajax-p ...

Menu toggle vanishes suddenly

Whenever I click the toggle button, I notice that the menu (which I have set to appear on toggle) only shows for a brief moment before disappearing. As a beginner in bootstrap, I am sure I might have made some obvious mistakes. Any assistance would be gr ...

What causes the appearance of an HTTP header error and how can we identify the bug?

I tried to convert XML to JSON using two files which are included here. However, I keep encountering an error. Despite searching on SO for solutions, I haven't been able to find the answers. main.js /** SET ENGINE TO PUG */ app.set("views", ...

Is it better to use scale.set() or simply increase the size of the model in Three.js?

When it comes to scaling 3D models in Three.js (or any other 3D renderers), what is considered the best practice? Recently, I encountered a situation where I loaded a model only to realize that its size was too small. In order to adjust the size, I used m ...

Ways to create dynamic functionality with JavaScript

I need to iterate through the document.getElementById("b") checked in a loop. Is this achievable? How can I implement it? <img class="img-responsive pic" id="picture" src="images/step1.png"> <?php //get rows query ...

What is the best way to include multiple ng-repeats within a single ng-repeat?

Hey, I'm facing quite a tricky situation with this grid and could use some assistance. I'm trying to figure out how to populate the data using ng-repeat. I've attached an image showcasing the desired layout of the grid and the order in which ...

Correct the positioning upon refreshing within a table containing multiple pages

Struggling with my code in index.php as it maintains the position inside the table but loses track of the web page number. The refresh is triggered by a button that updates a value in the selected row (in column B) by running a php script validation.php. I ...

Adding a border to the <area> element: A step-by-step guide

Can a border be added around an <area> element? This would be useful for testing an imagemap, however the following code does not achieve the desired effect: area { outline: 1px solid red; border: 1px solid red; } ...

Implement a loading spinner for autocompletion by utilizing an array as data source instead of relying on an

If you're interested in implementing autocomplete using an array instead of an in-memory web API, check out this thread for an example: Here's the updated search function in autocomplete.service.ts: search(filter: {name: string} = {name: '& ...

Obtain the URL for making an asynchronous request using PHP and SQL

I'm encountering some issues with a website I am attempting to update. A script named "jquery.script.js" is called in the head section containing some code. $.ajax({ url: 'function.js.php?option=urlget&id='+movie_id, ...

Encountering a "dependency resolution error" while deploying a React application with Parcel on Heroku

I've developed a compact application and I'm in the process of deploying it to Heroku. However, I keep encountering an error stating: '@emotion/is-prop-valid' dependency cannot be resolved. It's worth mentioning that this project d ...