我想在ng-repeat块中更改对象后,向ng-model对象添加属性“discountRate”。
选择选项后,ng-model会按预期更新。但“discountRate”不会作为属性添加。显然我错过了一些关于“范围”的东西。如果有人对此进行调查,我怎样才能将“discountRate”属性添加到ng-model中?
<form class="form-horizontal" ng-submit="addToInvoice()">
<div class="form-group">
<label for="inputService" class="col-sm-2 control-label">Service</label>
<div class="col-sm-4">
<select name="data.itemToSave" class="form-control" required="required"
ng-options="option.title for option in items.services track by option.id"
ng-model="data.itemToSave"></select>
</div>
</div>
<div class="form-group">
<label for="inputPrice" class="col-sm-2 control-label">Discount</label>
<div class="readonly" data-toggle="buttons">
<label class="btn btn-default" ng-class="{active: '!data.itemToSave.discountRate'}">
<input type="radio" ng-model="data.itemToSave['discountRate']" value="0">0%</label>
<label class="btn btn-default">
<input type="radio" ng-model="data.itemToSave['discountRate']" value="10">10%</label>
<label class="btn btn-default">
<input type="radio" ng-model="data.itemToSave['discountRate']" value="20">20%</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button type="submit" class="btn btn-default">Add to Invoice</button>
</div>
</div>
</form>
答案 0 :(得分:1)
删除data-toggle="buttons"
使其有效,无论是否有ui.bootstrap
ng-change,ng-click don't work with data-toggle="buttons" since v1.3.0