Modify content based on selected radio button (ANGULAR)

My goal is to have radio buttons that, when selected, will add the text from the input box to the respective section's unordered list as a list item.

<body ng-app="MyApp">
    <div ng-controller="MyController as myCtrl">
        <div class='wrap'>
                <p>Section 1<p>
                    <ul>
                        <li ng-repeat="item in myCtrl.items1">{{item}}</li>
                    </ul>
                <p>Section 2<p>
                    <ul>
                        <li ng-repeat="item in myCtrl.items2">{{item}}</li>
                    </ul>
                <p>Section 3<p>
                    <ul>
                        <li ng-repeat="item in myCtrl.items3">{{item}}</li>
                    </ul>
        </div>
        <div class='wrap'>
            File Name: <input type="text" ng-model="myCtrl.fileName">
            <button ng-click="myCtrl.addFile()">Add File</button>
            <div>
                <input type="radio" name="foldertoadd" ng-value="myCtrl.section1" ng-model="myCtrl.sectionSelected"> Section 1
                <input type="radio" name="foldertoadd" ng-value="myCtrl.section2" ng-model="myCtrl.sectionSelected"> Section 2
                <input type="radio" name="foldertoadd" ng-value="myCtrl.section3" ng-model="myCtrl.sectionSelected"> Section 3
            </div>
        </div>
    </div>
</body><!-- end of MyApp, angular ends here -->

In the controller, I've already set it up to retrieve the text from the input box and add it to section 1's list. Now, I need to implement functionality for the user to select a radio button to choose the desired section where the text should be added.

var myModule = angular.module("MyApp", []);

myModule.controller('MyController', function(){

    var self = this;

    self.items1 = ["File 1.1","File 1.2","File 1.3"];
    self.items2 = ["File 2.1","File 2.2","File 2.3"];
    self.items3 = ["File 3.1","File 3.2","File 3.3"];

    self.sectionSelected = false;

    self.addFile = function() {
        var textAdded = self.fileName;
        self.items1.push(textAdded);
    }

});

I've created a fiddle showcasing the functionality, but unfortunately, I'm experiencing difficulties loading AngularJS: https://jsfiddle.net/RL_NewtoJS/tx7novnb/10/

Answer â„–1

I managed to solve it by checking the ng-value of the radio button: https://jsfiddle.net/tx7novnb/13/

The issue was with the ng-value attribute of the radiobutton:

<input type="radio" name="foldertoadd" ng-value="myCtrl.item1" ng-model="myCtrl.sectionSelected"> Section 1

Additionally, in the function self.addFile, I added the following code snippet:

self.addFile = function() {
    var textAdded = self.fileName;
    self.sectionSelected.push(textAdded);
}

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

Guide to dynamically resizing the Monaco editor component using react-monaco-editor

Currently, I am integrating the react-monaco-editor library into a react application for viewing documents. The code snippet below showcases how I have set specific dimensions for height and width: import MonacoEditor from 'react-monaco-editor'; ...

Encountering an Injection module error in AngularJS version 1.4.8

Struggling to implement OAuth service in Angular 1.4.8 and encountering an error in the console: Error: http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=angularoauthexample…udflare.com%2Fajax%2Flibs%2Fangular.js%2F1.4.8%2Fangular.min.js%3A19%3A ...

Ways to manipulate controls in an individual row of a table with javascript

My table is receiving dynamically appended rows on button click at the client-side. Here's a link to see it in action: DEMO Each row has a button, and I want to be able to access the controls in the specific row where the button was clicked. How can ...

Preventing event bubbling/propagation in custom events: a step-by-step guide

Incorporating a module-project from Github into my Angular project, I am able to resize the DOM elements that are displayed on top of a div functioning as a drawing board. To configure my initial rectangles, I am utilizing a combination of mouseDown - mou ...

Creating a dynamic multi-select feature in AngularJS with ng-repeat

I'm relatively new to AngularJS and JavaScript, but I've managed to create a functional multi-select list. The ng-model linked to the dropdown is part of a "user" DTO object, specifically a property that stores an array of "groups" the user can j ...

Leveraging the powerful Google Maps API to enhance your mapping experience with

After making updates to my code, I managed to keep the Map intact while adding a script to place markers. Unfortunately, the step to add markers is not functioning properly. The data with coordinates is fetched from SQL, converted to JSON using C# and then ...

Angular: Designing personalized hyperlink overlays for text content with a filter

Currently, I am dealing with a json feed that provides information about cars. A portion of the text includes [VIN:'vin_number_is_here']Car make model here[/VIN]. To display this in an ng-repeat loop, I would like to use a filter to process the t ...

Error: The if statement is not providing a valid output

I am currently developing a basic price calculator that calculates the total area based on user input fields. While most of the program is functioning correctly, I am encountering an issue with the if statement that is supposed to determine the price rat ...

How to retrieve values from dynamically generated text boxes using ng-repeat in AngularJS

When using ng-repeat, I am able to display textboxes related to each item. Upon clicking the SaveAll button, I intend to retrieve all textbox values based on ITEM ID and save them to the database. <tr> <td> <table ng-repeat="item in ...

Show the dropdown menu with names from the array in the ajax response

<html> <select name="cars"> <option value="34">Volvo XC90</option> <option value="54">Saab 95</option> <option value="12">Mercedes SLK</option> <option value="10">Audi TT</option> </select> ...

Troubleshooting: Issue with running npm start | React app not loading

npm start command seems to be stuck at this particular point - https://i.sstatic.net/5NUVF.png The application is failing to load because of this issue. Here is the content of package.json file - { "name": "reacttest", "vers ...

Incorporating .json files into an HTML template with the help of an HTML form designed for selecting a particular

I am faced with a collection of various .json files that I wish to specify by name on an HTML page (local) form, enabling me to load this data onto a table. This is how my HTML form appears: <form> File: <input type="text" Id="file_name"&g ...

scrollbar is shy and not visible

I don't use CSS often, but I attempted to create a scrollable area with the following code. However, it seems to only hide the text that doesn't fit without providing a scrolling option. This behavior is consistent across Chrome, IE, and Firefox, ...

The performance of Node.js Knex SQL insert queries leaves much to be desired

I have created a simple login system that performs the following actions: Verifies if the username exists (works fine) Adds the username to the database After adding the username, I retrieve the id of the added username. Everything works smoothly on the ...

Avoiding clashes in the DOM caused by conflicts between ngAnimate and ngClass

Recently, I started experimenting with the ngAnimate library version 1.2.13 and encountered a problem where it disrupts my DOM when using the ngRepeat directive in conjunction with ngClass. It appears that there is a conflict arising when ngClass adds or r ...

Executing an external Python script through an HTML button from a location outside the Django project

I'm encountering an issue when attempting to run a Python script through an HTML button. The error message I receive is: module 'sys' has no attribute 'execute' In my views.py, I have the following code: from subprocess import r ...

How can an HTML5 application be configured to enable access to intranet and local files?

It's a known fact that accessing the local path of a file added using a file input field or drag-and-drop is not possible even with the new FileAPI. Whether this limitation is good, bad, or ugly is not up for debate. The FileAPI specs clearly state th ...

Revise Script to Duplicate Alt Attribute onto Miniatures

I'm customizing a gallery plugin for a website that I am currently developing, aiming to add support for titles. The script I am using can be found here: DEMO: http://jquery.malsup.com/cycle/pager2.html CODE: All the functionalities are in place e ...

Exploring JavaScript: Retrieving attributes from a JsonResult data structure

Is there a way to access all properties of an object returned from JsonResult in the client side, similar to using C# Reflection? ...

Issue encountered: Unable to load resource - ajax file upload failed due to net::ERR_SSL_BAD_RECORD_MAC_ALERT error

I've implemented an AJAX form file upload using jQuery. After testing my code across multiple computers and browsers, I've encountered an issue on one Windows 8 machine running Chrome where the upload functionality fails with the following error ...