[英]Radio Buttons ng-value, ng-model and ng-click
I have a simple form that renders items and provide radio buttons.我有一个简单的表单,可以呈现项目并提供单选按钮。 Radio buttons are rendered as expected.
单选按钮按预期呈现。 My goal is to get 'item.chosen' value in the selectRadioButton function. I am getting the item but item.chosen is undefined.
我的目标是在 selectRadioButton function 中获取“item.chosen”值。我正在获取该项目,但 item.chosen 未定义。 What am I doing wrong here?
我在这里做错了什么?
HTML: HTML:
<div class="item" ng-if="ctrl.items" ng-repeat="item in ctrl.items">
<input type="radio" ng-model="item.chosen"
ng-value=true ng-click="ctrl.selectRadioButton(item)">
</div>
this.selectRadioButton = function(item){ if(item.chosen) { console.log('Got the chosen value'); } }
Here is some sample code of how you should work with radio buttons on AnuglarJS.下面是一些示例代码,说明如何在 AnuglarJS 上使用单选按钮。
Controller: Controller:
angular.module('radioExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.color = {
name: 'blue'
};
$scope.specialValue = {
"id": "12345",
"value": "green"
};
}]);
HTML: HTML:
<form name="myForm" ng-controller="ExampleController">
<label>
<input type="radio" ng-model="color.name" value="red">
Red
</label><br/>
<label>
<input type="radio" ng-model="color.name" ng-value="specialValue">
Green
</label><br/>
<label>
<input type="radio" ng-model="color.name" value="blue">
Blue
</label><br/>
<tt>color = {{color.name | json}}</tt><br/>
</form>
Check documentation for more info查看文档以获取更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.