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/