在通过 ng-repeat 更改后,在 ng-model 对象中添加一个新的 属性

add a new property in ng-model object after it's been changed via ng-repeat

我想在 ng-repeat 块中更改对象后向 ng-model 对象添加 属性 "discountRate"。

Example 2

选择一个选项后,ng-model 会按预期更新。但是 "discountRate" 没有添加为 属性。显然我遗漏了一些关于 "scope" 的信息。有人会调查这个吗,我怎样才能将 "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>

删除 data-toggle="buttons" 使其工作,有或没有 ui.bootstrap

https://github.com/angular/angular.js/issues/4516