gpt4 book ai didi

javascript - ng-model 未选择单选按钮

转载 作者:行者123 更新时间:2023-12-01 03:51:48 26 4
gpt4 key购买 nike

我在 ng-repeat 中有一个输入类型的 radio 。整个 div 加载在弹出窗口中,因此我通过parentScope 访问 Controller 属性。

<div ng-repeat="name in parentScope.PatientInfo">
<input type="radio" id="select-radio-{{$index}}" ng-class="{'radio-btn':true, 'newpaymentmethod1' : true}"
ng-model="parentScope.nameObject" name="object">
</div>

我正在获取 parentScope.PatientInfo 的值,但我的输入类型单选按钮默认情况下或单击时均未选择。我尝试将 value 和 ng-value 赋予我的输入类型 radio ,但一切都是徒劳。

最佳答案

var app = angular.module('myApp', []);
app.controller('myController', function($scope) {

$scope.selected = {
"name": "",
"zipCode": "",
"addressType": "",
"message": ""
};
$scope.items = [{
"name": "newyork",
"zipCode": "80166",
"addressType": "shipToHome",
"message": "test"
}, {
"name": "toronto",
"zipCode": "80166",
"addressType": "shipToHome",
"message": "test"
}, {
"name": "california",
"zipCode": "80166",
"addressType": "shipToHome",
"message": "test"
}];
$scope.MessageDelivery = function(name) {
$scope.selected.message = "Will be Delivered to " + name;

};
$scope.getItems = function() {
return $scope.items;
};

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp">
<div ng-controller="myController">
<div>Which one?</div>
<label class="radio" ng-repeat="item in getItems()">
<input type="radio" ng-model="selected.name" name="itemOptions" ng-change="MessageDelivery(item.name)" value="{{item.name}}">{{item.name}} - {{item.zipCode}} - {{item.addressType}}
</label>
<hr />
<div>You picked: {{selected.name}} - {{selected.message}} </div>
</div>
</div>

关于javascript - ng-model 未选择单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43113496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com