Angular: Radio Buttons
directly binding value to model eliminates handling the selection event.
HTML
<div ng-controller="MyCtrl">
<label>
<input type="radio" ng-model="information.desc" ng-value="true" name="maklumat" ng-click="onChange()">False</label>
</br>
<label>
<input type="radio" ng-model="information.name" ng-value="true" name="maklumat" ng-click="onChange()">Yes</label>
<br />
<button ng-click="logInfo()">
Log model
</button>
</div>
CSS
html,input{
margin: 15px;
}
JavaScript
var myApp = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
//alert($scope.information.name + ":" + $scope.information.desc );
$scope.information = {name:true, desc: true};
//alert($scope.information.name + ":" + $scope.information.desc );
$scope.logInfo = function(){
//alert($scope.flag);
$scope.flag = false;
console.log($scope.information);
}
$scope.onChange = function(){
alert($scope.information.name + ":" + $scope.information.desc );
}
}