gpt4 book ai didi

javascript - 为什么 ng-model 不检查默认单选按钮?

转载 作者:行者123 更新时间:2023-12-03 04:40:22 24 4
gpt4 key购买 nike

下面是我正在工作的 fiddle :

http://jsfiddle.net/3c0dxf4d/

ng-model 有一个对象,ng-value 映射到对象,为什么我的默认值是 {"id":1,"name ":"比尔"} 默认情况下未选择。

最佳答案

看看这个 fiddle http://jsfiddle.net/roz98eda/

var app = angular.module("app", []);

app.controller("ctrl", function($scope) {
$scope.customers = [{
"id": 1,
"name": "Bill"
}, {
"id": 2,
"name": "Bob"
}, {
"id": 3,
"name": "Biff"
}];
$scope.customer = {};
$scope.currentCustomer = {
"id": 1
};

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="ctrl">
<table>
<tr ng-repeat="theCustomer in customers">
<td>
<input type="radio" ng-model="$parent.currentCustomer.id" ng-value="theCustomer.id">{{theCustomer.name}}</td>
</tr>
</table>
<br>
<div>{{currentCustomer}}</div>
</div>
</div>

关于javascript - 为什么 ng-model 不检查默认单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43118229/

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