简体   繁体   English

未选中angularjs单选按钮

[英]angularjs radio button not checked

I have a radio button inside ng-repeat functionality. 我在ng-repeat功能中有一个单选按钮。 So, it will create radio button on each step. 因此,它将在每个步骤上创建单选按钮。 But for some step radio button is getting checked and for some radio button is not getting checked even if we have data from backend. 但是对于某些步骤,即使我们有来自后端的数据,也要检查单选按钮,而对于某些单选按钮则不会检查。

Issue: For some steps radio button is not getting checked even if it has ng-modal value 问题:对于某些步骤,即使单选按钮具有ng-modal值,也不会得到检查

 <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <div ng-app=""> <div class="temp"> <label class="radio"> <input type="radio" ng-model="info.Unit" value="1" name="optradio-00">unit1</label> <label class="radio"><input type="radio" ng-model="info.Unit" value="0" name="optradio-00"> unit2</label> </div> <div class="temp"> <label class="radio"><input type="radio" ng-model="info.Unit" value="1" name="optradio-01">unit1</label> <label class="radio"><input type="radio" ng-model="info.Unit" value="0" name="optradio-01">unit2</label> </div> </div> </body> </html> 

radio image with value printed on top 顶部印有价值的无线电图像

You can use below concept to fire the event on ng-change 您可以使用以下概念在ng-change上触发事件

<div ng-controller="MyCtrl">
<input type="radio" ng-model="value" value="radiobutton1" ng-change='newValue(value)'>
<input type="radio" ng-model="value" value="radiobutton2" ng-change='newValue(value)'>
<input type="radio" ng-model="value" value="radiobutton3" ng-change='newValue(value)'>    
<hr> 
</div>

write the code in app.js 在app.js中编写代码

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.value= 'radiobutton1';

    $scope.newValue = function(value) {
       console.log(value);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM