angularjs 更新到 1.8 后单选按钮值未更新
Radio button value not updating after angularjs update to 1.8
AngularJS更新到1.8后,点击调用DayTypechange(2)
方法后单选按钮的值没有更新。这是我的 html:
<div class="btn-group btn-group-sm col-xs-11 col-md-10 select topmargine">
<div class="col-xs-6 col-sm-6 select">
<input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(1)' ng-class="{selected: fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="wholeDay" ng-value="'1'" />
<label class="col-xs-10 formtextNormal" for="wholeDay">Whole day(s)</label>
</div>
<div class="col-xs-6 select">
<input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(2)' ng-class="{selected: !fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="partDay" ng-value="'0'" />
<label class="col-xs-10 formtextNormal" for="partDay">Part day</label>
</div>
</div>
您应该考虑使用 ng-change 进行复选框、单选框和选择等输入点击。
angular.module('changeExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.confirmed = "No"
$scope.change = function() {
console.log('radio clicked of value ', $scope.confirmed)
};
}]);
<html ng-app='changeExample'>
<head><script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script></head>
<body ng-controller="ExampleController">
<label><input type="radio" ng-model="confirmed" value="Yes" ng-change="change()" name='changer' /> Yes</label>
<label><input type="radio" ng-model="confirmed" name='changer' value="No" ng-change="change()" />NO</label>
<hr><div>Current radio = {{confirmed}}</div>
</body></html>
AngularJS更新到1.8后,点击调用DayTypechange(2)
方法后单选按钮的值没有更新。这是我的 html:
<div class="btn-group btn-group-sm col-xs-11 col-md-10 select topmargine">
<div class="col-xs-6 col-sm-6 select">
<input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(1)' ng-class="{selected: fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="wholeDay" ng-value="'1'" />
<label class="col-xs-10 formtextNormal" for="wholeDay">Whole day(s)</label>
</div>
<div class="col-xs-6 select">
<input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(2)' ng-class="{selected: !fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="partDay" ng-value="'0'" />
<label class="col-xs-10 formtextNormal" for="partDay">Part day</label>
</div>
</div>
您应该考虑使用 ng-change 进行复选框、单选框和选择等输入点击。
angular.module('changeExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.confirmed = "No"
$scope.change = function() {
console.log('radio clicked of value ', $scope.confirmed)
};
}]);
<html ng-app='changeExample'>
<head><script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script></head>
<body ng-controller="ExampleController">
<label><input type="radio" ng-model="confirmed" value="Yes" ng-change="change()" name='changer' /> Yes</label>
<label><input type="radio" ng-model="confirmed" name='changer' value="No" ng-change="change()" />NO</label>
<hr><div>Current radio = {{confirmed}}</div>
</body></html>