将单选按钮值绑定到控制器(使用angularjs 1.5)

binding radio button value to the controller (using angularjs 1.5)

本文关键字:angularjs 使用 控制器 单选按钮 绑定      更新时间:2024-04-16

我在向控制器发送单选按钮值时遇到问题,这是我的html:

<input class="i-radio" name="_rate"  ng-model="rate"  ng-value="'-100'" type="radio" />-5 star (-100)</label>
<button class="btn btn-primary col-sm-offset-4" type="submit" ng-click="evaluation(rate)">Evaluez</button>

我的控制器:

 $scope.evaluation = function(rate){
    console.log(rate);
}

我的问题是rate.value总是未定义

我发现我的错误是在我的html中,类i-radio以某种方式阻止了对单选按钮的检查

没关系,只是你没有指定任何控制器,我想,试试我为你写的代码:

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<script>
var app = angular.module("angApp", []);
app.controller("angCtrl", function($scope) {
 $scope.evaluation = function(rate){
    console.log(rate);
}
});
</script>
<div ng-app="angApp" ng-controller="angCtrl">
<input class="i-radio" name="_rate"  ng-model="rate"  ng-value="'-100'" type="radio" />-5 star (-100)</label>
<button class="btn btn-primary col-sm-offset-4" type="submit" ng-click="evaluation(rate)">Evaluez</button>
</div>
</body>
</html>

希望帮助了你---