在Angular我有一组收音机? 如何找到至少有一个被选中?
HTML:
<html>
<head>
<script data-require="angular.js@1.4.6" data-semver="1.4.6" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app='jayApp' ng-controller='jayController'>
<h1>Angular radio group selected ??</h1>
<input type="radio" name="country" ng-model='country'> India
<input type="radio" name="country" ng-model='country'> UK
<input type="radio" name="country" ng-model='country'> Germany
<input type="radio" name="country" ng-model='country'> France
<br>
<br> A country selected ?? : {{country}}
</body>
</html>
Plunnker:http://embed.plnkr.co/cN6xhL/preview
答案 0 :(得分:2)
您需要为每个value
添加input
,以便有角色可以锁定,并且如果您只是想知道某些内容发生了变化,请使用ng-change。
<input type="radio" name="country" ng-model='country' value='india' ng-change="change()"> India
<input type="radio" name="country" ng-model='country' value='uk' ng-change="change()"> UK
<input type="radio" name="country" ng-model='country' value='germany' ng-change="change()"> Germany
<input type="radio" name="country" ng-model='country' value='france' ng-change="change()"> France