0

I have a scenario where any one protocol has to be configured on a device. A web UI will display all the options as a checkbox and I need to retrieve the protocol and device that was checked and send this data via http post to backend server. I am using HTML and AngularJS. Below is my code so far and please suggest if this can be done in a better way.

var Myapp = angular.module('Myapp', []);


Myapp.controller('CloudController', function($scope,$http)
 {
 $scope.execute = function(ImageLoc, protocol, device)
     {
    # HTTP request will be generated here 
     };
   });
<form>
<h3>Choose the protocol:</h3>
  <input type="checkbox" name="protocol" value=1> L3 Sanity <br>
  <input type="checkbox" name="protocol" value=2> L2 Sanity <br>
  <input type="checkbox" name="protocol" value=3> ROUTING <br>
  <input type="checkbox" name="protocol" value=4> STP <br>
  <input type="checkbox" name="protocol" value=5> VLAN <br>
  <input type="checkbox" name="protocol" value=6> Interface Scale <br>
  <input type="checkbox" name="protocol" value=7> VLAN SCALE <br>
  
<h3>Choose the Device:</h3>
  <input type="checkbox" name="device" value=1> DUT 1 <br>
  <input type="checkbox" name="device" value=2> DUT 2 <br>
  <input type="checkbox" name="device" value=3> DUT 3 <br>
  <input type="checkbox" name="device" value=4> DUT 4 <br>
  <input type="checkbox" name="device" value=5> DUT 5 <br>
  
<h3>Enter Image location:</h3> 
  <input type="text" ng-model="ImageLoc" />
  
  <p><input type="button" value="Launch" ng-click="execute(ImageLoc,protocol,device)"/></p>
</form>
Amith B
  • 57
  • 1
  • 11
  • I know how to generate the http request. I only need to know how to retrieve the options that were checked. – Amith B Jun 28 '17 at 12:53
  • 1
    create an isSelected property and attach it to each of then items. Iterate through the item list and check where isSelected is true – Laazo Jun 28 '17 at 12:54
  • Maybe this can help you: https://stackoverflow.com/questions/14514461/how-do-i-bind-to-list-of-checkbox-values-with-angularjs – Hannes Jun 28 '17 at 12:57
  • In this case you need to use a `select` element not multiple checkbox. Because you need to select only 1 option not multiple. If you must use checkbox then you need to handle an model with `ngChange`. – Burak Akyıldız Jun 28 '17 at 12:57

0 Answers0