我有一个表格,其中我有一组地址,有2组无线电按钮 - 一个告诉地址是否被占用,另一个告诉所有权(即租用或拥有)如果地址被占用
最初在渲染屏幕时,我将'Occupied'的默认值设置为'N',并且将取消选择和禁用'Ownership'。 仅当用户为“已占用”选择“Y”时,才会启用“所有权”并且默认值为“O”。
我在渲染屏幕时正确绑定默认值。
当我更改“占用”按钮的值时,问题就出现了,问题出在“所有权”单选按钮上。当通过鼠标单击更改所有权单选按钮值时,将发生数据绑定。但是当'ng-checked'表达式取消选择/选择它时,数据绑定不会发生。如何使数据绑定发生,即当'ng-checked'= false时获得“”,而ng-checked=true
时获得'O'(默认情况下ng-checked=true
时选择O)。
这是我的代码
<div class="row" ng-repeat="address in addresses ">
<label class="col-md-2 text-info">{{address.ref}}</label>
<label class="text-info">Occupied *</label>
<input type="radio" ng-model=" address.occupied " value="Y"/>
<label class="text-info">Inuse</label>
<input type="radio" ng-model=" address.occupied " value="N"/>
<label class="text-info">Not in use</label>
<label class="text-info"> Ownership</label>
<input type="radio" name="{{address.ref}}ownership" ng-checked=" address.occupied == 'Y'" ng-model="address.ownership" value="R" ng-disabled=" address.occupied == 'N'"/>
<label class="text-info">Rented</label>
<input type="radio" name="{{address.ref}}ownership" ng-checked=" address.occupied == 'Y'" ng-model="address.ownership" value="O" ng-disabled=" address.occupied == 'N'"/>
<label class="text-info">Owned</label>
</div>
$http.get('load').success(function(data){
$scope.addressConfiguration.addresses.push({ "ref" :"A234", "occupied": "N", "ownership":""}, {"ref": "A114", "occupied": "N", "ownership":""}, {"ref": "A278", "occupied": "N", "ownership":""}, {"ref": "A903", "occupied": "N", "ownership":""});
});
Plunker [link] http://plnkr.co/edit/aUeNV4EpnaV04TlquUHs?p=preview
答案 0 :(得分:0)
在data-ng-click属性中添加表达式修复了我的问题。
<input type="radio" ng-model=" address.occupied " value="Y" ***data-ng-click="address.occupied='Y'"***/>
<input type="radio" ng-model=" address.occupied " value="N" ***data-ng-click="address.occupied=''"***/>
在plunker [link] http://plnkr.co/edit/aUeNV4EpnaV04TlquUHs?p=preview
中找到解决方案