Anshul Singh Panwar Anshul Singh Panwar - 1 month ago 9
AngularJS Question

AngularJs how to call the value of a radio button?

</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Glossy: </label>
<div class="checkbox">
<label><input type="checkbox" value="">Yes</label>
<label><input type="checkbox" value="">No</label>
</div><br>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>

<script>
//document.getElementById("date").innerHTML = new Date();
var app = angular.module("myApp",[]);
app.controller("verify", function ($scope){

var verifydate = function(){
var name = $scope.ss;
if(ss.checked){
z = Date.parse(Date());
z = z + 86400000;
var mydate1 = new Date(z);
}
};


});
</script>


`How do you call the value of a radio button in angularJS and store it in a variable. I am trying to make this function in the controller so that i can print the delivery date in the span but I am not able to?

enter image description here

Answer

You can find all the necessary information in the documentation for input\[radio\]

Every input should have the same ng-model but with different value or ng-value

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.shirts = "A magnificient t-shirt with a unicorn on it !";//used with ng-value
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <input type="radio" id="poster" name="optradio" ng-model="option" value="poster">Posters
  <input type="radio" id="coffee" name="optradio" ng-model="option" value="coffee">Coffee mugs
  <input type="radio" id="shirt" name="optradio" ng-model="option" ng-value="shirts">T-shirts

  <p>You choosed : {{option}}</p>
</div>

Comments