pTutorial

New way to learn Programming

Angularjs Radio Button Default Checked

HTML

<html>
<head>
<link href="http://freeonlinecompiler.ptutorial.com/
css/bootstrap.min.css" rel="stylesheet" type="text/css">
<script src="http://www.ptutorial.com/angularjs/
angular.min.js" type="text/javascript"></script>
<script type="text/javascript" src="app-radio-checked.js"
></script>
</head> 
<body>
<div ng-app="ukapp">
<div ng-controller="ukCtrl" ng-cloak> 

<h4>Angularjs radio button checked value</h4>
<div class="radio">
<label><input type="radio" ng-checked="1" ng-init="uk='Apple'"  
ng-model="uk"  value="Apple">Apple</label>
</div>
<div class="radio">
<label><input type="radio" ng-model="uk" 
value="Banana">Banana</label>
</div>



<h4>Another deafult radio checked example</h4>
<div class="radio">
<label><input type="radio" ng-checked="1" 
ng-model="uk1"  value="Nokia">Nokia</label>
</div>
<div class="radio">
<label><input type="radio" ng-model="uk1" 
value="Sony">Sony</label>
</div>


<div class="right-fix dwn-nav com-marg">
<a class="btn btn-danger"  ng-click="save()">Save</a> 
<a class="btn btn-danger" href="">Cancel</a></div>            
</div>
</div>
</body>
</html>

AngularJS

var ukapp = angular.module('ukapp', []);
ukapp.controller('ukCtrl', function ($scope, $http, $timeout) {
$scope.uk='';
$scope.uk1='Nokia';
$scope.save=function (){
    if($scope.uk==''){
        alert("Please choose one");
    }else{
        alert("You have choosed :"+$scope.uk);
        alert($scope.uk1);
    }
}
});

Download

See Also


QUOTES OF THE DAY

Wicked men obey from fear, good men from love

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER