I have two radio buttons pass
and fail
.
How to get value of selected radio button.
<div class="col-md-4">
Result
<div class="radio">
<label><input type="radio" name="rdoResult">pass</label>
</div>
<div class="radio">
<label><input type="radio" name="rdoResult">fail</label>
</div>
</div>
Do I need to use ng-model or something else. In jquery I know the things well not in angularjs.
Here is your javascript
<script>
aap=angular.module('myApp',[])
.controller('myCtrl',["$scope",function($scope){
$scope.change='data';
$scope.getVal=function(){
console.log($scope.changedVal);
$scope.change=$scope.changedVal;
}
}]);
</script>
and your html
<body ng-app="myApp">
<h1>{{1+1}}</h1>
<div class="col-md-4" ng-controller="myCtrl">
Result
<div class="radio">
<label><input type="radio" name="rdoResult" ng-model="changedVal" value="pass" ng-click="getVal()">pass</label>
</div>
<div class="radio">
<label><input type="radio" name="rdoResult" ng-model="changedVal" value="fail" ng-click="getVal()">fail</label>
</div>
{{change}}
</div></body>
working demo
Hope this is what you are looking for.
Both should have same ng-model
with different ng-value
(meant for use with select option
s or radio
button), so that the selected value will be changed on result
$scope variable and you can grab that value inside a controller on form submit or button click.
Markup
<div class="col-md-4">
Result
<div class="radio">
<label>
<input ng-model="result" type="radio" name="rdoResult" ng-value="'pass'">
pass
</label>
</div>
<div class="radio">
<label>
<input ng-model="result" type="radio" name="rdoResult" ng-value="'fail'">
fail
</label>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With