我有一个填充客户列表的ngRepeat,如下所示:
<div ng-repeat="terr in terrData.data">
<div class="customer-row" ng-click="clickCustomerSelect(terr)">
<input class="customer-radio" type="radio" name="customer-select" ng-model="selectedCustomerRow" value="{{terr.customerID}}">
<div class="contact-data-column">{{terr.custNm}}</div>
<div class="primaryphone-data-column">{{terr.primaryPhone}}</div>
<!-- other customer data -->
</div>
</div>
客户行div上有一个click事件,表示如果单击该行,则应检查该行的单选按钮。
此处显示的基本控制器逻辑:
$scope.clickCustomerSelect = function(customer){
$scope.selectedCustomerRow = customer.customerID.toString();
//Other business logic
};
我看到无论何时单击客户行(而不是单选按钮),模型都会正确更新,并且会检查与该值对应的单选按钮。请注意,这是预期的功能。
我看到的问题是,如果您手动检查单选按钮(即不单击该行),模型将不再响应单击该行的更新。
我想知道一旦你选择单选按钮,你是否会以某种方式超出角度范围?
编辑:样本模型
terrData.data = [{
"customerID": 1,
"companyName": "Name 1",
"custNm": "Blank",
"primaryPhone": "111-111-1111"
}, {
"customerID": 2,
"companyName": "Name 2",
"custNm": "Blank",
"primaryPhone": "111-111-1112"
}, {
"customerID": 3,
"companyName": "Name 3",
"primaryPhone": "111-111-1113"
}];
答案 0 :(得分:2)
$scope.selectedCustomerRow = customer.customerID.toString();
替换为:
$scope.selectedCustomerRow = customer.customerID;
onclick with it set selectedCustomerRow。
HTML中的
<input class="customer-radio" type="radio" name="customer-select" ng-model="selectedCustomerRow" value="{{terr.customerID}}">
替换为:
<input class="customer-radio" type="radio" name="customer-select" ng-model="$parent.selectedCustomerRow" value="{{terr.customerID}}">
答案 1 :(得分:0)
可能你的问题是:https://stackoverflow.com/a/17607794/170407
简短回答:ng-model
几乎总是需要一个点。