How to get selected radio button value in AngularJS?




How to get selected radio button value in AngularJS?

How to get selected radio button value in AngularJS?

I will help to get checked radio button value in angular js app. we can get selected radio button value in controller of angular.

Here we will create simple example. we will create simple for and submit button. When you click on submit button then one angular controller method will call and we will get selected radio button value using angularjs $scope variable.

Also Read:- How to add Days, Hours, Minutes, and Seconds to Datetime in PHP

<!doctype html>
<html>
   <head>
      <title>How to get selected radio button value in AngularJS?</title>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
   </head>
   <body ng-app='myapp'>
      <h1>How to get selected radio button value in AngularJS?</h1>
      <div ng-controller="myCtrl">
         <div class="radio">
            <label><input type="radio" ng-model='sex' ng-value='"male"' name="sex">Male</label>
         </div>
         <div class="radio">
            <label><input type="radio" ng-model='sex' ng-value='"female"' name="sex">Female</label>
         </div>
         <button ng-click="submitResult()">See Result</button>
      </div>
   </body>
   <script type="text/javascript">
      var app = angular.module('myapp', []);
      app.controller('myCtrl', function ($scope, $location) {
         $scope.sex = 'male';
         $scope.submitResult = function() {
            alert($scope.sex);
         };
      });
   </script>
</html>

 


Author Biography.

Lokesh Gupta
Lokesh Gupta

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working in the information technology and services industry. I enjoy solving complex problems within budget and deadlines putting my skills on PHP, MySQL, Python, Codeigniter, Yii2, Laravel, AngularJS, ReactJS, NodeJS to best use. Through Knowledge of UML & visual modeling, application architecture design & business process modeling. Successfully delivered various projects, based on different technologies across the globe.



News & Blogs

04dd32c0108d23bf51249aeab490ad84.png

Get a head start with trending Nodejs developer...

To build and run applications, you need different types of runtime environments that help in seve...

99c65279a4f62ad85fb5b8b340077bb3.png

How to Integrate Payumoney Payment Gateway in L...

I am going to explain How to Integrate Payumoney Payment Gateway in Laravel 5. Most of thing are ...

045b052a4c56e8680d2177403a62bb23.png

Important Things You Need To Know About Agile D...

In 2001, a gathering of 17 programming engineers met and talked about another way of thinking in ...